ASP tip example: several lines of code to prevent repeated submission of forms

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 (the number of code lines exceeds dozens !!) 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.

China site. Long SITE

File 1: Form file formtest. asp

Reference content is as follows:

<%
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 handler 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
%>

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.