Using several lines of ASP code to prevent a form from being committed multiple times

Source: Internet
Author: User
In many cases, it is necessary to prevent the same form from being submitted multiple times, and many people's implementations are more complex (code counts more than dozens of lines!!) The following provides a way to use just a few lines of code, easily to prevent users from refreshing multiple submission forms and to repeat them multiple times with the back button.
Form file formtest.asp
<%randomize ' initial generation random number seed
Num1=rnd () ' produces random numbers NUM1
Num1=int (26*NUM1) +65 ' modifies NUM1 range so that it is a-Z-wide ASCII code to prevent table Single-name errors
Session ("antry") = "test" &CHR (NUM1) ' produces a random string
% >
< form name= "test" action= "testact.asp" method= "POST" >
Your name:< input type= ' text ' name= ' size=30 > ' note the Random form item name is used in the bank
< input type= ' submit ' value= ' submitted ' >
</form >
Form Handler testact.asp
<%
Teststr=request.form (Session ("Antry"))
If teststr= "" Then
Response.Write "did not fill in the name or repeat the submission"
' Cause the user did not fill in the name, or the form is repeated (the flag is null for session ("Antry"))
Else
Response.Write Teststr
Session ("antry") = "' Submit successfully, empty session (" Antry "), in case of repeated submission!!
End If
% >
In this case, you only need to randomize the form item name of a required item so that you do not have to randomize all the form items.
Welcome to my personal homepage http://swuse.yeah.net



Related Article

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.