I also try to find a good way to prevent double records generation when a user dbl-click on a submit button.
It's not about the PRG issue that is easily fixed by redirection.
So, regards on this basic concern, the solution with HTTPRedirect on server-side doesn't help.
On client-side, I found two problems when I disable the button before submit:
- With HTML5 validation, the
form.submit() will be interupted by browser if the form is invalid => submit button is still disabled=true.
- When the user submit the form and do a back in browser history, the DOM will be loaded from browser's cache => submit button is still
disabled=true.
So here is my workaround for the first client-side problem (HTML5 validation):
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 try to find a client-side workaround for the second client-side problem (browser cache the DOM) but nothing worked (onbeforeunload, ...).
So the workaround I currently use for "browser cache" issue is add a @never_cache decoration on the top of concerned views (from server-side, indicate to client-side to not caching). Please let me know if you have a better workaround.
Last but not least, I would really appreciate to fix this issue on server side.
The CSRF solution seems not suitable since a CSRF token is generated by session (not for each form).
So here is the status of my work and my question:
- Fix this issue on client-side is OK but doesn't look like a good solution to me. How could we avoid to validate this multiple form submition on server-side?
Let me know if you have a good solution for that.
Edit 1:
May be a small part of the answer: Synchronizer (or Déjà vu) Token
But I didn't find any implemantation of that in Django.