ASP code to prevent forms from repeating submissions

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.

File One: Form file formtest.asp

  <%
   Randomize '初始代随机数种子
   num1=rnd() '产生随机数num1
   num1=int(26*num1)+65 '修改num1的范围以使其是A-Z范围的Ascii码,以防表单名出错
   session("antry")="test"&chr(num1) '产生随机字符串
   %>
   <form name="test" action="testact.asp" method="post">
   你的名字:<input type='text' name='' size=30>  '注意本行中使用了随机表单项名
   <input type='submit' value='提交'>
   </form>

Form Handler testact.asp

  <%
   teststr=request.form(session("antry"))
   if teststr="" then
    response.write "没有填写姓名或重复提交"
    '由于用户没有填写名字,或表单被重复提交(标志为session("antry")为空)引起
   else
    response.write teststr
    session("antry")=""  '提交成功,清空session("antry"),以防重复提交!!
   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

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.