Home>Article>Backend Development> Analyze Examples of ThinkPHP's Methods to Prevent Duplicate Submissions of Forms
This article summarizes and analyzes ThinkPHP's method of preventing repeated submission of forms. Share it with everyone for your reference. The details are as follows:
Why are there duplicate forms?
During development, if a new or For the modified form, after completing the database operation in the background, we set whether to jump to other pages or return to this page. At this time, clicking the browser's back button before submitting or refreshing the page will cause the form form to be submitted repeatedly, that is, this record Will be added or modified twice.
The reason that causes the form to be submitted repeatedly is that the form submitted for the first time will be cached in the memory and will not disappear until the next time the page is submitted or the page is closed or redirected to other pages. When the self-call returns, the data in the memory is still there. At this time, the submitted code in the page can still detect the submitted value, which will cause the effect of repeated submission.
Related learning recommendations:php programming(video)
How to solve it?
To summarize the online solutions and your own tests, you can use the following methods:
Method 1:The simplest: after submitting the page Go to another page instead of this page. For example, if your page address is
//m.sbmmt.com/
, then the form action address of the page can be For another processing address, if an error is returned like