• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
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


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2021 MyBB Group.