How to prevent multiple submissions of the same form?

Source: Internet
Author: User
Method (1): Change the attribute of the button to disable.
<Script language = "JavaScript">
Function button1_onclick ()
{
Form1.button1. Disabled = true
}
</SCRIPT>
<Form name = form1>
<Input type = button name = button1 onclick = "button1_onclick ()" value = "OK">
Method 2 ):
In many cases, it is necessary to prevent the same form from being submitted multiple times. Many people's implementation methods are complicated ( Code More than dozens of rows !!) The following provides a method that uses only a few lines of code to easily prevent users from refresh the submitted form multiple times and use the back button to submit the form multiple times.
Form file formtest. asp
<% Randomize 'initial random number Seed
Num1 = RND () 'generates a random number num1
Num1 = int (26 * num1) + 65' modify the num1 range to make it an ascii code for the A-Z range to prevent form name errors
Session ("antry") = "test" & CHR (num1) 'generates a random string
%>
<Form name = "test" Action = "testact. asp" method = "Post">
Your name: <input type = 'text' name = ''size = 30> 'note that the random form item name is used in this row.
<Input type = 'submit 'value = 'Submit'>
</Form>
Form Processing Program Testact. asp
<%
Teststr = request. Form (Session ("antry "))
If teststr = "" then
Response. Write "no name or repeated submission"
'The user did not enter the name, or the form was submitted repeatedly (marked as Session ("antry") is empty ).
Else
Response. Write teststr
Session ("antry") = "" 'submitted successfully. Clear SESSION ("antry") to prevent repeated submission !!
End if
%>
This is useless/
3. Q: How can I have two submit buttons for a form?
A: It can be implemented using JavaScript.
<HTML>
<Head>
<SCRIPT>
Function submitit1 ()
// Submit to program 1 for processing
{
Document. myform. Action = "http://www.site.com/cgi1.php"
Document. myform. Submit ();
}
Function submitit2 ()
// Submit it to program 2 for processing
{
Document. myform. Action = "http://www.site.com/cgi2.php"
Document. myform. Submit ();
}
</SCRIPT>
</Head>

<Body>
<Form name = "myform" method = post>
Username: <input type = text name = text1>
Password: <input type = password name = text2>
<Input type = button value = "Submit 1" onclick = "submitit1 ()">
<Input type = button value = "Submit 2" onclick = "submitit2 ()">
</Form>
</Body>
</Html>

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.