Ask a Question
Advertise on boostr.in
Organizational Research By
Surprising Reserch Topic
question about how redirects should work
question about how redirects should work ¬†using -'php,forms,codeigniter'
So I have a web app that i'm working on with a form that requires all of the fields to be populated before submitting. If you try to submit the app without a field being populated, it loads the page again with the errors. Once you fill all the fields in and click submit, it does a redirect to the same page and shows a message which is generated from flashdata. See simplified example below.
¬†¬†// make the 'quality' field required
¬†¬†$this->form_validation->set_rules('quality', 'Quality', 'required');
¬†¬†if($this->form_validation->run() == FALSE) //if the fields are NOT filled in...
¬†¬†¬†¬†$this->load->view('form'); //reload the page ¬†
¬†¬†else ¬†// if the fields are filled in...
¬†¬†¬†¬†// set success message in flashdata so it can be called when page is refreshed.
¬†¬†¬†¬†$this->session->set_flashdata('message', 'Your rating has been saved');
Now to illustrate my issue, lets say I'm on the 'home' view and I navigate to the 'form' view. If i populate the 'quality' field and click submit, i get redirected back to the 'form' view, with a success message. If i click the back button on the browser, it takes me back to the 'home' view. EVERYTHING WORKS AS EXPECTED
Now lets say i'm on the 'home' view and I navigate to the 'form' view. If i click the submit button without populating the 'quality' field, the 'form' view is reloaded again and it displays the error message. If i then populate the 'quality' field and click submit, i get redirected back to the 'form' view with a success message. The problem is, if i click the back button on the browser, it now takes me back to the form page with the error, and I have to click the back button again to get back to the 'home' view.
What is the best coding practice so that if a user submits the form with errors, it will display the errors, and if they fix the errors and submit the form again it will display the success message and if they click back on the browser, it will take them back to the 'home' view??
Sep 15, 2015
to add a comment.
Related Hot Questions
Government Jobs Opening