Note that there are some explanatory texts on larger screens.

plurals
  1. POQuestion about how redirects should work
    text
    copied!<p>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.</p> <p>Welcome controller:</p> <pre><code>function show_view() { $this-&gt;load-&gt;view('form'); } function process_form() { // make the 'quality' field required $this-&gt;form_validation-&gt;set_rules('quality', 'Quality', 'required'); if($this-&gt;form_validation-&gt;run() == FALSE) //if the fields are NOT filled in... { echo form_error('quality'); $this-&gt;load-&gt;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-&gt;session-&gt;set_flashdata('message', 'Your rating has been saved'); redirect(welcome/show_view); } } </code></pre> <p>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</p> <p>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.</p> <p>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??</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload