Form Validation Errors

I've just started using CI and already I'm loving the validation class and the form helper.
I am aware you can show individual error messages in custom delimiters:
&lt;?php echo form_error('field name', '<div class="error">', '</div>'); ?&gt;

However, after searching Google and the forum, I can't find anything on styling the individual fields which failed validation.
Any suggestions?

... more of a CSS issue...

perhaps, you can have multiple "error" classes in you style sheets.


&lt;?php echo form_error('field1', '<div class="error1">', '</div>'); ?&gt;
&lt;?php echo form_error('field2', '<div class="error2">', '</div>'); ?&gt;
&lt;?php echo form_error('field3', '<div class="error3">', '</div>'); ?&gt;

[eluser]Simian Studios[/eluser]
[quote author="_steve" date="1276574179"]styling the individual fields which failed validation.
Any suggestions?[/quote]

So, you want to apply a class to the actual form input itself, if I understand correctly.

Not sure if this is the "correct" way to do it, but it will work..

&lt;input type="text" name="name" id="name"&lt;?php if(form_error('name') !== ''){ ?&gt; class="error" &lt;?php } ?&gt;value="&lt;?php echo set_value('name'); ?&gt;" /&gt;

The trick is that form_error() will return a string if there is an error, or a null value if not, so we can test against that and set the class accordingly.

Sorry daelsepara, my question was a little unclear, but Simian Studios has what I was looking for.
From what I could see from the user guide, there is no "correct" way, so this will do just fine.

Thanks both.

[eluser]Simian Studios[/eluser]
You're welcome Smile

Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  

  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2021 MyBB Group.