CodeIgniter, form helper - Adding classes to the elements

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

echo form_input($data);

reference

Share:
12,032
Kevinvhengst
Author by

Kevinvhengst

Updated on June 14, 2022

Comments

  • Kevinvhengst
    Kevinvhengst almost 2 years

    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!

  • Kevinvhengst
    Kevinvhengst over 10 years
    Thx! I've read the docs as well, but thought my approach was going to work aswell, since i actually saw the classes and styling while inspecting the element. On a side note, you should edit and add a comma after the value and remove the one behind style :) Thx for your help mate!
  • spreaderman
    spreaderman over 7 years
    How would you add 'disabled' to the above? There is no identifier, just 'disabled'