How to avoid duplicate submission of forms

Source: Internet
Author: User
Tags define variable
Repeat | Repeat submit have you ever encountered a "repeat submission" problem? It is not difficult to solve the problem. Here's a simple way to avoid duplicate submissions of the same form.
First, we can define a session variable to hold the submit sequence number of a form. Here I define "$userLastAction". Then add a hidden variable to the form and set the value to $userlastaction+1:
<input Type=hidden name=lastaction value=<? = $userLastAction +1?>>
Finally, determine if the form has been submitted before processing the submission:
if ($lastAction > $userLastAction and Inputisvalid (...)) {
$userLastAction + +; Serial number plus 1.
Working with form data
}

Original:
Avoid multiple form submissions
Submitted By:douglas E. Cook
date:07/26/00 19:46
Does your database suffer from "duplicate post" syndrome? The cure isn ' t too difficult. Here are a simple way to prevent users from submitting the same form multiple times.

Declare a session variable to store a serial number for each form. I call Mine "$userLastAction." Then, in every form where duplicate submission are a problem, include a hidden field, and set the value to $userLastAction + 1:

<input type=hidden name=lastaction value=<?= $userLastAction +1?>>

Finally, verify that's form has not been previously submitted before on the acting:

if ($lastAction > $userLastAction and Inputisvalid (...)) {
$userLastAction + +; Increment Serial Number
Act on Form
}

From: Phpbuilder
This is just a little trick to avoid repetitive submissions of a form. So how much can prevent some of the phenomenon of irrigation, in addition, sometimes because of network conditions and other reasons, users do not know whether the submission is successful, will also submit the same form.
The main principle of this technique is not to allow users to return back back to submit again, that is, back and back to amend the submission is not allowed, but also can not avoid ctrl-c/ctrl-v irrigation methods. Whether there is no use, or to see the likes of you webmaster.


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.