![]() |
Simple Form Validation Mod: Check if error exists - Printable Version +- CodeIgniter Forums (https://forum.codeigniter.com) +-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20) +--- Forum: Archived Libraries & Helpers (https://forum.codeigniter.com/forumdisplay.php?fid=22) +--- Thread: Simple Form Validation Mod: Check if error exists (/showthread.php?tid=45757) |
Simple Form Validation Mod: Check if error exists - El Forum - 10-04-2011 [eluser]Kinsbane[/eluser] So, currently my form is setup to where labels and inputs are housed within a container. My CSS is setup to show a light red background, a red border on the input, and red text if the container div has the class "error". This is well and good, but I realized that while using CI's Form Validation, I have no way of checking if the error of a field is actually present, in order for me to be able to assign the "error" class to my containing div. I have searched around for this, but didn't have much luck in finding a similar solution. So, this is my simple fix. It's more than likely not best practice, but this is how I thought to do it. Code: class MY_Form_validation extends CI_Form_validation Then, in my view: Code: <div class="container<?php echo ($this->form_validation->error_exists('email') ? ' error' : ''); ?>"> Hope this helps others, though by now they've probably rolled their own solution for this. ![]() |