UPDATE
You want to publish the form, verify it, and then show the form again with validation errors if the validation fails, or show something completely different if the validation passes.
The best way to do this is to send the form back to yourself. Thus, the action of your form will be action="" . Thus, in your method, you can check if the form has been submitted and determine what to do there:
// in my form method if ($this->input->post('submit')) // make sure your submit button has a value of submit { // the form was submitted, so validate it if ($this->form_validation->run() == FALSE) { $this->load->view('myform'); } else { $this->load->view('formsuccess'); } } else { // the form wasn't submitted, so we need to see the form $this->load->view('myform'); }
OLD ANSWER
You can always pass the current URI in a hidden field in the form:
<input name="redirect" type="hidden" value="<?= $this->uri->uri_string() ?>" />
And then redirect if validation fails:
redirect($this->input->post('redirect'));
Or you can set the redirect URL in the flashdata session variable:
// in the method that displays the form $this->session->set_flashdata('redirect', $this->uri->uri_string());
And then redirect if validation fails:
redirect($this->session->flashdata('redirect'));
source share