Use several lines of ASP code to prevent forms from being submitted multiple times

Source: Internet
Author: User
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 Generation Seed
Num1 = RND () ' Generate random number num1
Num1 = Int ( 26 * Num1) + 65 ' Modify the range of num1 to make it an ascii code for the A-Z range to prevent form name errors
Session ( " Antry " ) = " Test " & CHR (Num1) ' Generate 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 a name or the form was submitted repeatedly (marked as Session ("antry") is empty ).
Else  
Response. Write Teststr
Session ( " Antry " ) = "" ' Submitted successfully. Clear the session ("antry") to prevent repeated submission !!
End   If  
% >  

Here, you only need to randomize a required project form item name, and do not have to randomize all form items.

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.