Prevent Form Duplicate Submit
Scenes
- click
submit
button multiple times when network delay - refresh page after clicking submit button
- after submit, click
back
button to back to previous page and submit again
Solutions
There are two points to prevent duplicating form submission: front-end and back-end.
Front-end
Disable submit
button via javascript after clicking it.
Back-end
Use session
- create a
token
on the server-side and save it tosession
- send this
token
to the hidden field of form - submit this token together with the form data
- if this token is not the same as server-side’s or there is no token in the session or there is not token in the form, then this is duplicate submit,
- otherwise it is normal submit and clear session’s token.
Struts
In struts, there is token
interceptor which can be used to handle multiple form submission problem.
References
Written on August 18, 2019