Press enter too fast, leading to repeated submission solution

Source: Internet
Author: User
The carriage return is too fast, leading to repeated submission. how can I solve this problem? 1. I must press enter to SUBMIT; 2. the SUBMIT is dimmed after the request is blocked, but press enter to SUBMIT the request, php prevents repeated submission of Forms & nbsp; Solution 1: The cookie mechanism is introduced to solve the problem of submitting page code as follows. php code: & lt; formid = & q press enter too fast, leading to repeated submission
How can I solve this problem? thank you.

1. I must press enter to submit the statement;
2. the SUBMIT becomes grayed out after the request has been blocked, but it will still be submitted by pressing enter.

------ Solution --------------------
Php prevents repeated forms


Solution 1: Introduce the cookie mechanism
The code for submitting the page is as follows:

Setcookie ("onlypost", 'T'); // Set the cookie, which can contain a time value. For example, some forums can store some of your basic information to prevent bumping.
?> The code for processing page B. php is as follows:
If ($ _ COOKIE ['onlypost'] ='t '){
Print_r ($ _ COOKIE );
// Process submitted content if the verification is successful
Print "OK ";
Setcookie ("onlypost", 'F'); // you can delete the cooike value.
}?>
Body
The disadvantage of the above processing: if the client disables cookies, this method will not work, please note.
Solution 2: Use session (this is the same as the JSP processing method)
Using the PHP Session function, you can avoid repeated forms. The Session is stored on the server. during PHP running, you can change the Session variable. The next time you access this variable, you get a new value. therefore, you can use a Session variable to record the value submitted in the form. if the value does not match, it is considered that the user is submitting the form repeatedly.
Code of page:
Session_start (); // Generate a random number based on the current SESSION
$ Code = mt_rand (usd00 );
$ _ SESSION ['code'] = $ code; // Save the random number to the session
?>
Page B:
Session_start ();
If (isset ($ _ POST ['originator']) {
If ($ _ POST ['originator'] = $ _ SESSION ['code']) {
Echo "OK ";
Unset ($ _ SESSION ["code"]); // clear it and press F5.
} Else {
Echo "Please do not refresh this page or submit the form repeatedly ";
}}?>
Solution 3: perform redirection on the server
If (isset ($ _ POST ['action']) & $ _ POST ['action'] = 'submitted '){
// Process the data. for example, after inserting the data, immediately go to another page.
Header ('Location: submits_success.php '); // The effect is similar to sendRedirect in JSP.
}


------ Solution --------------------
Someone asked me before, in extreme cases! For example, the post interval is small! And large.
What should I do?


------ Solution --------------------
If the customer has no opinion, do not press enter: onsubmit = "return false ;"
------ Solution --------------------
Not that complicated. JS is simple.

That's simple.
------ Solution --------------------
Disable the button and press enter to trigger the button. I don't believe you can submit it again.
Another method is $ ("# OK: not (. btn-disable)"). live ("click", function ()
{
$ (This). addClass ("btn-disable ");
}
------ Solution --------------------
Why cannot I "submit again?
------ Solution --------------------
Discussion

Haha, I often test it.
In an input box and a submit button, enter a number, press enter, and write an UPDATE in the background, qty = qty + number of inputs. you can test it according to your method, the number of results.

I have tried several
1. onsubmit event, sumbmit1 (name of the submit button). disabled = true;
2. put a hidden button in form with the value of a session. after submitting the button, determine whether the two values are the same ......

------ Solution --------------------

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.