I am also trying to find a good way to prevent the creation of double entries when the user dbl-click on the submit button. This is not about a PRG problem that is easily fixed by redirection.
So, given this basic problem, a solution with HTTPRedirect on the server side does not help.
On the client side, I found two problems when I disabled the button before sending:
- When validating HTML5,
form.submit() will be intercepted by the browser if the form is invalid => the submit button is still disabled=true . - When the user submits the form and returns to the browser history, the DOM will be loaded from the browser cache => submit button is still
disabled=true .
So here is my workaround for the first client problem (HTML5 check):
isFormHtml5Valid(form) { for(var el of form.querySelectorAll('input,textarea,select')){ if(!el.checkValidity()) return false; } return true; } mySubmitButton.onclick = function() { if(this.form && isFormHtml5Valid(this.form)) this.disabled=true; this.form.submit(); }
I'm trying to find a client side workaround for a second client side problem (DOM browser cache), but nothing works (onbeforeunload, ...). Therefore, the workaround that I currently use for the "browser cache" is to add the @never_cache decoration at the top of the corresponding views (on the server side, specify on the client side, so as not to cache). Please let me know if you have a better workaround.
Last but not least, I would really like to fix this problem on the server side . The CSRF solution seems unusable because the CSRF token is generated by the session (not for each form). So, here is the status of my work and my question:
- Fixing this problem on the client side is fine, but it doesn’t look like to me. How could we avoid checking this multiple form submission on the server side?
Let me know if you have a good solution for this.
Edit 1: Maybe a small part of the answer: the synchronizer token (or Déjà vu)
But in Django, I did not find any effect.
Gosti Sep 07 '16 at 11:06 2016-09-07 11:06
source share