Welcome Guest, Not a member yet? Register   Sign In
How to change a color of the inputbox on form_error validation?
#1

[eluser]term25[/eluser]
I would like to change a class of the input element (e.g. in css style sheet then I can add border 1px solid red for input element etc.), when there is a validation error. How to achieve this? I have not found any solution for CodeIgniter yet. Thanks in advance.

Example of my code:
Code:
<tr>
  <td>
    Title
  </td>
  <td>
    &lt;?php echo form_input('title', set_value('title'), "class = 'title'"); ?&gt;
    &lt;?php echo form_error('title', '<span class="error">', '</span>'); ?&gt;
  </td>
</tr>
#2

[eluser]CroNiX[/eluser]
Code:
//Check to see if there was an error for this field, if there was change the class to "error"
$title_class = (form_error('title') !== '') ? 'error' : 'title';


Then assign the class to your form_input() in the 3rd parameter.
#3

[eluser]term25[/eluser]
Thanks a lot, it's working perfectly.
#4

[eluser]Aken[/eluser]
You should use valid HTML in the third parameter, though.

Code:
&lt;?php echo form_input('title', set_value('title'), 'class="title '.$title_class.'"'); ?&gt;




Theme © iAndrew 2016 - Forum software by © MyBB