Welcome Guest, Not a member yet? Register   Sign In
Access validation errors in a helper
#1

[eluser]richzilla[/eluser]
Is there any way to access form validation errors in somewhere other than a view? I want to access any potential form validation errors in a helper?
#2

[eluser]Twisted1919[/eluser]
Code:
if ( ! function_exists('_get_validation_object'))
{
    function &_get_validation_object()
    {
        $CI =& get_instance();

        // We set this as a variable since we're returning by reference
        $return = FALSE;

        if ( ! isset($CI->load->_ci_classes) OR  ! isset($CI->load->_ci_classes['form_validation']))
        {
            return $return;
        }

        $object = $CI->load->_ci_classes['form_validation'];

        if ( ! isset($CI->$object) OR ! is_object($CI->$object))
        {
            return $return;
        }

        return $CI->$object;
    }
}

And the access to the validation object in your functions:


function form_error($field = '', $prefix = '', $suffix = '')
    {
        if (FALSE === ($OBJ =& _get_validation_object()))
        {
            return '';
        }

        return $OBJ->error($field, $prefix, $suffix);
    }


Maybe you can take a look at the form_helper.php, it has it all Wink




Theme © iAndrew 2016 - Forum software by © MyBB