Welcome Guest, Not a member yet? Register   Sign In
red_background on validation
#1

[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!
#2

[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 .
#3

[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!
#4

[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 '';
    }    
}




Theme © iAndrew 2016 - Forum software by © MyBB