pmoubed
pmoubed

Reputation: 3922

How to avoid form re-submission if browser back button is selected?

Let's consider a scenario like below :

  1. Symfony2 provides a removal form for an entity
  2. User selects remove button
  3. Symfony2 controller will remove the entity and redirect the User to confirmation page
  4. If user select browser back button he/she will see the record and removal form again
  5. Selecting Remove button will throw an exception because it was removed already

What is the best way to avoid back button and re-submissions ?

The controller for this question is the same as here.

Upvotes: 2

Views: 1555

Answers (1)

Elnur Abdurrakhimov
Elnur Abdurrakhimov

Reputation: 44841

All data changing requests should be done using the POST method — or PUT, POST or DELETE if you're doing it in the RESTful way. After such a request, redirect to a GET page. If a user will push the back button, the browser will show a warning saying that the request should be sent again and that it can lead to unwanted results. If the user insists on resending the request, she should get a 404 error page because she's trying to do stuff with something that doesn't exist anymore.

Upvotes: 4

Related Questions