Welcome Guest, Not a member yet? Register   Sign In
validation_errors empty after validation failed
#1

[eluser]Unknown[/eluser]
--- edit ---
I've submitted a bug report for this issue: https://github.com/EllisLab/CodeIgniter/issues/598
------------

I've updated to 2.0.3, I'm running a simple form

Code:
$this->form_validation->set_error_delimiters( '<div class="error">', '</div>' );
$this->form_validation->set_rules( 'name', 'name', 'required');
$this->form_validation->set_rules( 'start-date', 'start date', 'required');
$this->form_validation->set_rules( 'end-date', 'end date', 'required');

if ( $this->form_validation->run() === FALSE ){
echo 'errors'
print_r( validation_errors() );
}
else {
}

this code above prints "errors" (so I know that validation failed) but no actual error text is printed. Going into the validation_errors function I see that _get_validation_object( always returns FALSE

the form_validation object has the following fields

Code:
[_error_array] => Array
        (
            [start-date] => The start date field is required.
            [end-date] => The end date field is required.
        )

    [_error_messages] => Array
        (
        )
    [error_string] =>

the _error_array is correct as the 'name' field was filled in but the start-date and end-date fields were not - but there's no error_string set.

--- addition ---

I just checked and the following

Code:
echo $this->form_validation->error('start-date');

works fine (from within the controller)

--- addition 2 ---

this is under PHP Version 5.3.2-1ubuntu4.9

it seems that form_helper.php:1040 is failing even though the values are actually set.

the following fixes the issue:

Code:
function &_get_validation_object()
{
$CI =& get_instance();

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

if ( !$CI->load->is_loaded('form_validation'))
{
  return $return;
}
$object = 'form_validation';
if ( ! isset($CI->$object) OR ! is_object($CI->$object))
{
  return $return;
}
return $CI->$object;
}




Theme © iAndrew 2016 - Forum software by © MyBB