5

In the early days of the web it was a problem that clicking the browser's Back button after clicking Submit could cause the form to be resubmitted so one might, for instance, end up with a double purchase.

This does not seem to be a problem any longer. How was it fixed? Do individual sites have to work around this or did browsers change?

2 Answers 2

7

One way to prevent this is to use the POST/Redirect/GET pattern.

Instead of directly sending a 200 after receiving the POST request, the server sends a 303 (or 302) redirect instead. The client follows it and gets (via GET) a 200 then. Refreshing this page repeats the last GET, not the previous POST.

For implementation questions, see the Stack Overflow tag "post-redirect-get".

3
  • And in regards to the direct question, when you press Back in the browser you go back to the initial page, not the intermediate POST request. Nov 30, 2015 at 1:18
  • one reason why people don't use the post-redirect-get pattern is to avoid the need for the user to fill the same form again in case something fails in the form submission. AFAIK, Ajax form submits cannot follow the post-redirect-get pattern Sep 23, 2021 at 13:54
  • It's not the answer to original question. PRG stands for the case with page refresh, not Back previous page Dec 28, 2022 at 16:06
0

I've used a javascript POST of the form data followed by a js re-direct. Using the back button doesn't cause those forums to be re-submitted.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.