![]() |
Form Validation Errors - Printable Version +- CodeIgniter Forums (https://forum.codeigniter.com) +-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20) +--- Forum: Archived General Discussion (https://forum.codeigniter.com/forumdisplay.php?fid=21) +--- Thread: Form Validation Errors (/showthread.php?tid=31317) |
Form Validation Errors - El Forum - 06-14-2010 [eluser]_steve[/eluser] 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: Code: <?php echo form_error('field name', '<div class="error">', '</div>'); ?> However, after searching Google and the forum, I can't find anything on styling the individual fields which failed validation. Any suggestions? Form Validation Errors - El Forum - 06-14-2010 [eluser]daelsepara[/eluser] ... more of a CSS issue... perhaps, you can have multiple "error" classes in you style sheets. e.g. Code: <?php echo form_error('field1', '<div class="error1">', '</div>'); ?> Form Validation Errors - El Forum - 06-15-2010 [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.. Code: <input type="text" name="name" id="name"<?php if(form_error('name') !== ''){ ?> class="error" <?php } ?>value="<?php echo set_value('name'); ?>" /> 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. Form Validation Errors - El Forum - 06-15-2010 [eluser]_steve[/eluser] 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. Form Validation Errors - El Forum - 06-16-2010 [eluser]Simian Studios[/eluser] You're welcome ![]() |