Summary of methods to prevent users from submitting forms repeatedly

Summary of methods to prevent users from submitting forms repeatedly

Duplicate form submission is the most common and troublesome problem in multi-user web applications. There are many application scenarios that may encounter duplicate submission problems, such as:

Click the Submit button twice. Click the Refresh button. Using the browser back button to repeat previous actions results in duplicate form submissions. Use your browser history to submit the form repeatedly. The browser repeats the HTTP request.

Several ways to prevent duplicate form submission

1. Disable the submit button . Use Javascript to disable the submit button after the form is submitted. This approach prevents impatient users from clicking the button multiple times. But there is a problem. If the client disables Javascript, this method will be invalid.

I mentioned in my previous article that using some Jquery plug-ins can have good effects.

2.Post/Redirect/Get mode . Performing a page redirect after submission is called the Post-Redirect-Get (PRG) pattern. In short, when the user submits the form, you perform a client-side redirect to the submission success information page.

This can avoid repeated submission caused by users pressing F5, and there will be no warning about repeated submission of the browser form. It can also eliminate the same problem caused by pressing the forward and back buttons of the browser.

3. Store a special flag in the session . When the form page is requested, a special string of characters is generated, stored in the session, and placed in a hidden field of the form. When accepting and processing form data, check whether the identification string exists, immediately delete it from the session, and then process the data normally.

If it is found that there is no valid flag string in the form submission, it means that the form has been submitted and the submission is ignored.

This gives your web application a more advanced level of XSRF protection.

4. Add constraints in the database. Add a unique constraint or create a unique index in the database to prevent duplicate data. This is the most effective way to prevent duplicate submission of data.

The above is an introduction to these four methods. If you have better solutions, please let me know. This article will continue to be updated.

<<:  Let IE6, IE7, IE8 support CSS3 rounded corners and shadow styles

>>:  Detailed explanation of CSS child element fixed positioning solution relative to parent element

Recommend

How to view Linux ssh service information and running status

There are many articles about ssh server configur...

Packetdrill's concise user guide

1. Packetdrill compilation and installation Sourc...

A very detailed explanation of Linux C++ multi-thread synchronization

Table of contents 1. Mutex 1. Initialization of m...

How to use native JS to implement touch sliding monitoring events

Preface I wrote a small demo today. There is a pa...

vue+ts realizes the effect of element mouse drag

This article example shares the specific code of ...

Detailed Analysis of or, in, union and Index Optimization in MySQL

This article originated from the homework assignm...

How to set up the use of Chinese input method in Ubuntu 18.04

In the latest version of Ubuntu, users no longer ...

A brief analysis of crontab task scheduling in Linux

1. Create a scheduling task instruction crontab -...

Vue implements graphic verification code

This article example shares the specific code of ...

MySQL trigger usage scenarios and method examples

trigger: Trigger usage scenarios and correspondin...

MySql Installer 8.0.18 Visual Installation Tutorial with Pictures and Text

Table of contents 1. MySQL 8.0.18 installation 2....

Analysis of the principle of Mybatis mapper dynamic proxy

Preface Before we start explaining the principle ...

Analysis of the locking mechanism of MySQL database

In the case of concurrent access, non-repeatable ...

HTML implementation of a simple calculator with detailed ideas

Copy code The code is as follows: <!DOCTYPE ht...