CodeIgniter Forums
red_background on 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: red_background on validation (/showthread.php?tid=23862)



red_background on validation - El Forum - 10-23-2009

[eluser]Unknown[/eluser]
Ok so here goes.

I' have a pretty simple form, and I would like on validation that if the field is required or has an error on the field that the background of the field changes to red. I'm pretty sure there is a simple way to do that but I can't seem to be able to find it in the user_guide!!

Thank you for the help!


red_background on validation - El Forum - 10-23-2009

[eluser]Twisted1919[/eluser]
I guess you have two ways of doing this .
1. Javascript - use jQuery and execute the form via ajax .
2. Use sessions to keep track of your validation, based on that, you would change the background of your field .

If i were you, i would stick to the first option which is more simple .


red_background on validation - El Forum - 10-23-2009

[eluser]Unknown[/eluser]
ok thank for the reply... Right now, I'm addind a class on form_error. But I guess your way is simpler I'll give it a try!


red_background on validation - El Forum - 10-28-2009

[eluser]Spicer[/eluser]
This is what I do.

Code:
<?php
if(validation_errors())
   echo '<div id="formMessage" class="message ui-corner-all feedbackNegative"><strong>Please correct the errors below.</strong></div>';
?&gt;

&lt;?=form_input("Email", set_value("Email"), 'class="field ui-corner-all ' . error_class('Email') . '"')?&gt;
&lt;?=form_error('Email', '<div class="error">', '</div>')?&gt;


if ( ! function_exists('error_class'))
{
    function error_class($elm, $error = 'error')
    {
        $tmp = form_error($elm);
        if(! empty($tmp))
            return $error;
        else
            return '';
    }    
}