Several solutions to prevent repeated submission of forms

Source: Internet
Author: User

The problem of repeated submission is often overlooked in B/S system development, but it is often a headache for programmers. According to Murphy's Law, if you do not do a mechanism to prevent repeated submissions, user behavior will often cause you trouble, and then wait for the product manager to complain. Below, I will summarize several common methods to prevent repeated submission of forms in the B/S system:

1. Control on the page. Are users afraid to click the submit button twice? Use javascript to control the submission. Are you afraid of repeated submission due to user withdrawal? Open a new page. In short, you need to imagine all possible operations on the user's page, and eliminate these operations that easily lead to bugs.

2. session control. If you cannot avoid repeated submission operations, add a token. The specific code is available on the Internet. The principle is that a token is generated when the user submits the token for the first time and is saved in the session. The token is compared during each submission. If the token is the same for two submissions, the statement is submitted repeatedly.

3. Jump Control. Generally, when I submit the statement, I will return the result to make it easier to use forward (internal redirection) instead of redirect (external redirection), because I will give some error messages based on the returned results. However, when using internal redirection, there will be a problem, that is, after the user submits the file, click the refresh button in the browser, and the last submitted operation will be resent once (although the browser prompts, but you cannot expect the user to see the prompt ). Therefore, the better way is to use the external redirection method to go to the next page after submission, so that the user refresh will also refresh the next page to open the operation.

PS. Someone may ask how to transmit the returned result parameter when using external redirection. It is difficult and inconvenient to include parameters after the link. We recommend that you use cookies to save the result status. They are saved on a temporary basis and cleared once used.

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.