Welcome Guest, Not a member yet? Register   Sign In
Styling CI form_input
#1

[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.
#2

[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.
#3

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

[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');
#5

[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]
#6

[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');
            }

        }
#7

[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]




Theme © iAndrew 2016 - Forum software by © MyBB