I am using Codeigniter’s validation class to validate my form. Could you please tell me how to redirect to the previous page from controller if found any validation error?
In my controller:
if ($this->form_validation->run() == FALSE){
//**** Here is where I need to redirect
} else {
// code to send data to model...
}
UPDATE
You want to post a form, validate it, then show the form again with the validation errors if validation fails, or show something entirely different if validation passes.
The best way to do this is to post a form back to itself. So the action of your form would be
action="". This way, in your method, you can check to see if the form was submitted, and determine what to do there:OLD ANSWER
You can always pass the current URI in a hidden field in the form:
And then redirect if the validation fails:
Or you can set the redirect url in a flashdata session variable:
And then redirect if the validation fails: