• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Form Validation in a Library - please help

[eluser]Sean Downey[/eluser]

I've had a look around but couldn't find anything about this.

I am trying to get form validation with the new form_validation class working from inside a library.

The problem is that the actual validation is working fine but then when I try to display the errors in the views the "form_error" and "validation_errors" functions will not display the errors.

// inside the library constructor
    $this->CI = &get;_instance();

if ($this->CI->form_validation->run() == FALSE) {
  // Errors
  print_r($this->CI->form_validation->_error_array); - This does show the errors
  echo validation_errors(); - this doesn't return anything :-(

The validation_errors function is not finding the validation_object

if (FALSE === ($OBJ =& _get_validation_object()))
  return '';

Does anyone know how I can get around this?

try instead:
echo validation_errors();

print_r validation_errors();

or for example:
print_r form_error('username');
where useranme is a 'name' of a field

Hope it helps!

[eluser]Sean Downey[/eluser]
[quote author="hugle" date="1249914968"]
try this:
print_r validation_errors();

Thanks but the validation object isn't found inside those functions to they return blank.

Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  

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