Love Fuel?    Donate

FuelPHP Forums

Ask your question about FuelPHP in the appropriate forum, or help others by answering their questions.
Validation errors
  • How can I get a simple array of errors when validating a form? My code: $validate = Validation::factory(); $validate->add_field('email', 'Email address', 'required');
    $validate->add_field('password', 'Password', 'required'); if(!$validate->run()) {
    print_r($validate->errors());
    } else {
    echo 'success';
    } I was expecting a simple array of errors, however I get a mass of recursive arrays and a debug message P.S. The code button doesn't seem to work
  • Errors are returned as Validation_Error objects, they have a __toString() method so if you just echo them (or cast to string in another way) they'll output as the error messages you're expecting.
  • I tried to do that but it just prints Array(); Could you show me an example using the code I put above? Thanks in advance
  • NM, got it working
  • It returns an array of Validation_Error objects, so something like:
    foreach ($val->errors() as $e)
    {
        echo $e;
    }
    

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

In this Discussion