Welcome Guest, Not a member yet? Register   Sign In
Check if a form field has an error
#1

[eluser]Joseph Wensley[/eluser]
Is there a to check if a form field has an error? I don't care what the error is I just need to know if there is any error for the field.

I extended the form helper with this function but I'm not sure if there are cases where it will fail.
Code:
function field_has_error($field)
    {
        if (FALSE === ($OBJ =& _get_validation_object()))
        {
            return TRUE;
        }
        
        if ( ! isset($OBJ->_field_data[$field]['error']) OR $OBJ->_field_data[$field]['error'] == '')
        {
            return FALSE;
        }
        else
        {
            return TRUE;
        }
    }
#2

[eluser]hugle[/eluser]
Hey,

I simply do: <?php if (form_error('contact_email')) echo ' error'; ?>
If I want to add error class for example
#3

[eluser]Brad K Morse[/eluser]
Check out http://ellislab.com/codeigniter/user-gui...ationrules

You can set rules for each field, then test to make sure all fields passed validation.

Also check out an example http://ellislab.com/codeigniter/user-gui...l#tutorial




Theme © iAndrew 2016 - Forum software by © MyBB