CodeIgniter Forums
Form Validation: return calues for rules? - 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: Form Validation: return calues for rules? (/showthread.php?tid=43254)



Form Validation: return calues for rules? - El Forum - 07-05-2011

[eluser]mindph[/eluser]
Hi

Is it possible somehow, to have the form validator return which rule was failing validation?

The purpose why I could need this is simply: I dont want to display only the errors, but also hilight the field what failed validation.
So that I could get something like
Code:
if($this->form_validation->rule('firstName') == FALSE){
$formData['firstName'] = array('style' => 'background-color: red');
}
I am not sure if you get what I mean... oO


Form Validation: return calues for rules? - El Forum - 07-05-2011

[eluser]misplacedme[/eluser]
Check out the section labeled "Showing Errors Individually" in the form validation page.

Code:
<h5>Username</h5>
&lt;?php echo form_error('username'); ?&gt;
&lt;input type="text" name="username" value="&lt;?php echo set_value('username'); ?&gt;" size="50" /&gt;



Form Validation: return calues for rules? - El Forum - 07-05-2011

[eluser]mindph[/eluser]
Okay thanks that looks cool.

Gonna like CI!


Form Validation: return calues for rules? - El Forum - 07-06-2011

[eluser]mindph[/eluser]
BTW The userguide tells me only about these values to set in an array.
Code:
$data = array(
              'name'        => 'username',
              'id'          => 'username',
              'value'       => 'johndoe',
              'maxlength'   => '100',
              'size'        => '50',
              'style'       => 'width:50%',
            );

echo form_input($data);
But class is also possible
Code:
'class' => 'classname'
Could be told in the User Guide too.