Love Fuel?    Donate

FuelPHP Forums

Ask your question about FuelPHP in the appropriate forum, or help others by answering their questions.
show form field error and populate field with data user inputted before it returned error
  • I was looking thru the documentation and could not figure out how to display right next to the field that had the error, but could display the error. I am not using the fieldset class, should I be to accomplish the above? Also, if a user inputs data, but it did not meet the specified requirement, how do I re-populate that field with what the user previously typed in? Another thing I should be using fieldset for? Another thing about displaying errors, how can you display all field errors with just one line of code, I only know how to do it individually like this:
    echo $val->errors('age');
    echo $val->errors('weight');
    echo $val->errors('height');
    
  • You can get the input from the Validation instance $val->input('age') as described in the docs: http://fuelphp.com/docs/classes/validation/validation.html#usage If you define your forms using the Fieldset class this can be done easier, just call ->repopulate() on the form. Form field errors can be shown all at once using $val->show_errors(). You also said you couldn't figure out how to show them individually next to the form but you do know how to show them individually, so I'm not sure what you're missing there?
  • I can display the errors in the controller individually, but not within the view.
  • Pass the Validation instance to the View using $view->set('val', $val, false) (have to disable output encoding to allow it through) or fetch it in the View using Validation::instance(). After that you can use the $val->error() method.

Howdy, Stranger!

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

In this Discussion