Repeated form submission is the most common problem in multi-user web applications and causes a lot of trouble. There are many application scenarios that encounter duplicate submission problems, such as:
Click the Submit button twice. Click the Refresh button. Repeat previous actions using the browser back button, resulting in repeated submission of the form. Repeat submission forms using browser history. Repeated HTTP requests from the browser.
Several ways to prevent repeated submissions of forms
1. Disable the submit button . Use Javascript to make the submit button disable after the form is submitted. This method prevents impatient users from clicking buttons multiple times. But there is a problem. If the client bans Javascript, this method will be invalid.My previous article said that using some Jquery plugins works well.
2.Post/Redirect/Get mode . Perform page redirection after submission, which is called Post-Redirect-Get (PRG) mode. In short, when the user submits the form, you perform a client redirect and go to the submission success information page.This can avoid repeated submissions caused by users pressing F5, and there will be no warnings of repeated submissions of browser forms, and can also eliminate the same problems caused by forward and backpression of browsers.
3. Store a special logo in the session . When the form page is requested, a special character flag string is generated, which is present in the session and placed in the hidden field of the form. When accepting processing form data, check whether the identification string exists and delete it from the session immediately, and then process the data normally.If you find that there is no valid flag string in the form submission, it means that the form has been submitted and this submission is ignored.
This gives your web application more advanced XSRF protection.
4. Add constraints in the database. Add unique constraints in the database or create unique indexes to prevent duplicate data. This is the most effective way to prevent repeated submissions of data.The above is an introduction to these 4 methods. If you have a better solution, please tell me, and this article will be updated continuously.