Repeated form submission is one of the most common and troublesome issues in multi-user Web applications. There are many application scenarios that will encounter repeated submission issues, such:
Click Submit twice.
Click Refresh.
Use the browser back button to repeat the previous operation, resulting in repeated form submission.
Use the browser history to repeat the submission form.
Repeated HTTP requests in the browser.
Several methods to prevent repeated submission of forms
Disable the submit button. After the form is submitted, use Javascript to make the submit button disable. This method prevents users from clicking the button multiple times. But there is a problem. If the client disables Javascript, this method will be ineffective.
I have mentioned in my previous articles that Jquery plug-ins have good results.
Post/Redirect/Get mode. Execute page redirection after submission. This is the so-called Post-Redirect-Get (PRG) mode. In short, after a user submits a form, you can execute a client redirection and go to the successful submission information page.
This avoids repeated submission by pressing F5, and does not trigger the warning of repeated submission by browser form. It also eliminates the same problem caused by pressing forward and backward by browser.
Store a special flag in the session. When a form page is requested, a special character flag string is generated, which exists in the session and is stored in the hidden field of the form. When accepting and processing form data, check whether the identification string exists, delete it from the session immediately, and then process the data normally.
If no valid flag string is found in the Form submission, it indicates that the form has been submitted and this submission is ignored.
This gives your web application more advanced XSRF protection.
Add constraints to the database. Add a unique constraint to the database or create a unique index to prevent duplicate data. This is the most effective way to prevent repeated data submissions.