Let’s consider a scenario like below :
- Symfony2 provides a removal form for an entity
- User selects remove button
- Symfony2 controller will remove the entity and redirect the User to confirmation page
- If user select browser back button he/she will see the record and removal form again
- 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.
All data changing requests should be done using the
POSTmethod — orPUT,POSTorDELETEif you’re doing it in the RESTful way. After such a request, redirect to aGETpage. 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 a404error page because she’s trying to do stuff with something that doesn’t exist anymore.