Several methods to prevent repeated submission of forms

Source: Internet
Author: User

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.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.