![]() |
Dynamic class: Form Validation - 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: Dynamic class: Form Validation (/showthread.php?tid=49954) |
Dynamic class: Form Validation - El Forum - 03-08-2012 [eluser]Samus[/eluser] i'm trying to add a class depending on whether my input elements have passed validation and can't quite think how to do this. Here's a snippet of my view: Code: <span class="formf <?= (form_error(('content')) ? "control-group error" : ""); ?>"> When the validation is run, and an input element does not pass validation the classes 'control-group error' is appended on the span tag. That works all fine an dandy. But what I want it to do is check if an input element has passed validation and if it has then append the classes 'control-group success' on the span element. But obviously on page load, because no errors were returned it will append 'control-group success'. How would I make it so that it only does that after the element has gone through validation? Or can somebody suggest another method of doing this? Dynamic class: Form Validation - El Forum - 03-08-2012 [eluser]achilleusrage[/eluser] One thing you could do is check for some other input (a hidden field) that flags if your form has been submitted. Then, if that flag exists, do your if your check to determine which CSS class to show. Dynamic class: Form Validation - El Forum - 03-08-2012 [eluser]Samus[/eluser] [quote author="achilleusrage" date="1331257658"]One thing you could do is check for some other input (a hidden field) that flags if your form has been submitted. Then, if that flag exists, do your if your check to determine which CSS class to show.[/quote] Now that you mention that, I just thought of running a check to see if anything was posted before going on to do the validation check. Thanks! Updated code in case anybody has a similar issue: Code: <span class="formf <?= ($this->input->post() ? (form_error(('content')) ? "control-group error" : "control-group success") : ""); ?>"> |