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.