Search code examples
phpcsscodeignitercodeigniter-form-helper

CodeIgniter, form helper - Adding classes to the elements


So i created a form with the CodeIgniter Form helper. I'm trying to give some form elements a class, but something strange happens. I do it like this:

echo form_input('title', $this->input->post('title'), 'class="titleInput"');

When i inspect the element it actually shows the class is there:

enter image description here

but it doesn't take any of the property's given in the CSS file. Also when i do something ugly like:

echo form_input('title', $this->input->post('title'), style="height=30px");

When i inspect the element i get this:

enter image description here

But it doesn't actually do anything with the styling given.

Hopefully someone can give me a hand here!


Solution

  • $data = array(
              'name'        => 'title',
              'value'          => $this->input->post('title'),
              'class'       => 'titleInput',
              'style'       => 'height:30px'
            );
    
    echo form_input($data);
    

    reference