Form validation: style input fields on error |
[eluser]drcosmo[/eluser]
Hey, I generated a form using the form_helper and i'm using the form validation class to validate the form. This works very well. Is it possible to style the input-fields that generated a validation error? I'd like to add a 'class=error' attribute to the invalid input-fields. This way i can show a smooth red border on the incorrect input-fields. Thanks!
[eluser]Cayson[/eluser]
Yes, this is possible. You have to set the error delimiters. This let's you convert the default Code: <p></p> Code: <span class='form_error'></span> http://ellislab.com/codeigniter/user-gui...delimiters
[eluser]drcosmo[/eluser]
Thanks, but that's not what i meant. I already show a div with a summary of all the errors. What i want (extra) is something like this: Code: <input type="text" name="name" value="" id="name" /> becomes Code: <input type="text" name="name" value="" id="name" class="error" /> when an error occurs for this field.
[eluser]Cayson[/eluser]
Yeah, that's in the guide. Right below delimiters. You use form_error instead of validate_errors in the view page. http://ellislab.com/codeigniter/user-gui...dualerrors Code: <?php echo form_error('field name', '<div class="error">', '</div>'); ?>
[eluser]drcosmo[/eluser]
Thanks, it works. this is my code: Code: $options = array( |
Welcome Guest, Not a member yet? Register Sign In |