CodeIgniter Forums
Styling CI form_input - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23)
+--- Thread: Styling CI form_input (/showthread.php?tid=22918)



Styling CI form_input - El Forum - 09-23-2009

[eluser]doubleplusgood[/eluser]
Hi there,

Relatively simple question - i'm trying to find out how I can add a CSS Class or ID to a form_input like this;

Code:
<?=form_input('first_name', set_value('first_name'));?>

Grateful for any solution.

Thanky.


Styling CI form_input - El Forum - 09-23-2009

[eluser]ElShotte[/eluser]
If theyre all going to look the same, you can style the BASE input class (standard look for ANY fields on the page). Easier and faster that way too.


Styling CI form_input - El Forum - 09-23-2009

[eluser]guillermo, out of repose[/eluser]
That's in the user guide, bro: http://ellislab.com/codeigniter/user-guide/helpers/form_helper.html


Styling CI form_input - El Forum - 09-23-2009

[eluser]doubleplusgood[/eluser]
Hi,

I tried the way from the user guide first, but it gave an undefined variable error.

Using the following code in the view;
Code:
<?=form_input($data);?>

and the following code in controller;
Code:
$data = array(
                'name' => 'last_name',
                'class' => 'text',
                'value' => 'last_name');



Styling CI form_input - El Forum - 09-23-2009

[eluser]guillermo, out of repose[/eluser]
how are you loading the view? If you're setting $data in the controller, then you need to load the view this way in your controller (also in the user guide):

[pre]
$data = array(
'name' => 'last_name',
'class' => 'text',
'value' => 'last_name');

$this->load->view('your_view', array('data'=>$data));
[/pre]


Styling CI form_input - El Forum - 09-23-2009

[eluser]doubleplusgood[/eluser]
This is how I am loading the View in my controller for signup;

Code:
function signup()
        {
            $this->load->library('form_validation');

            if ( $this->form_validation->run() == FALSE )
            {
                $this->load->helper('form');

                $view_data['view_file'] = 'account/signup';
                $this->load->view('layout', $view_data);
            }
            else
            {
                $email = $this->input->post('email');
                $password = $this->input->post('password');
                $first_name = $this->input->post('first_name');
                $last_name = $this->input->post('last_name');
                
                $user = array(
                            'email' => $email,
                            'password' => $password,
                            'first_name' => $first_name,
                            'last_name' => $last_name
                        );
                
                $this->auth->signup($user);
                redirect('account');
            }

        }



Styling CI form_input - El Forum - 09-23-2009

[eluser]guillermo, out of repose[/eluser]
You're not defining $data in your controller.

Just do this and you'll be fine:

[pre]<?=form_input(array('name' => 'last_name', 'class' => 'text', 'value' => 'last_name'));?>[/pre]