Welcome Guest, Not a member yet? Register   Sign In
Returning after form_validation
#1

[eluser]Funky Fresh[/eluser]
Hey Hey,

Im new to CI ... Im writing my first app and using the form_validation for the first time.

if the validation fails, is it best to use return; or redirect(''); to go back to the same page.

for example.

Code:
if($this->form_validation->run()){
            //redirect('');
            //return;
        } else {
        
        }

Which of the return methods would be best to use.

Cheers,
#2

[eluser]JoostV[/eluser]
If validation returns false, stay in the same page and show the form again.

If validation returns true, do what you have to do with the form results and redirect to another page. (so the form cannot be reposted by hitting F5 repeatedly)
#3

[eluser]Funky Fresh[/eluser]
So it would be best to do the following?

Code:
if($this->form_validation->run()){
          //Validation worked, redirect to another page which processes data
          redirect('do_something');
        } else {
          // Validation failed, return
          return;
        }
#4

[eluser]JoostV[/eluser]
More like this, imho.
Code:
if ($this->form_validation->run()) {
    //Validation worked, process and redirect
    $this->model->process_data($_POST);
    redirect('do_something', 'refresh');
}
else {
    // Validation failed, show form again
    $this->load->view('view_that_shows_your_form');
}




Theme © iAndrew 2016 - Forum software by © MyBB