Restricting duplicate submission of the same form in an ASP application

Source: Internet
Author: User

We encounter countless forms on the Internet every day, and most of them do not restrict users from submitting the same form multiple times. The lack of such restrictions can sometimes produce unexpected results, such as repeating a subscription to a mail service or repeating a ballot. Perhaps some ASP beginners are not clear how to limit the repeated submission of the same form in ASP applications, so here we introduce a simple way to prevent users from submitting the same form multiple times during the current session in an ASP application.

This work is mainly composed of four subroutines, in a simpler application, you simply put the code in the containing file directly referenced can be, for those more complex environment, we at the end of the article to give some suggestions for improvement.

First, the basic work process

Let's discuss the four subroutines in turn.

(i) initialization

Here we want to save two variables in the Session object, where:

⑴ each form corresponds to a unique identifier called a FID, in order to make the value unique to use a single counter.

⑵ each time a form is successfully committed, it must store its FID in a Dictionary object.

We use a dedicated process to initialize the above data. Although each subroutine will call it later, it is actually executed once per session:

Sub InitializeFID()
 If Not IsObject(Session("FIDList")) Then
  Set Session("FIDList")=Server.CreateObject("Scripting.Dictionary")
  Session("FID")=0
 End If
End Sub

(ii) Generate unique identifiers for the form

The following function, Generatefid (), is used to generate a unique flag for a form. The function first adds the FID value to 1, and then returns it:

Function GenerateFID()
 InitializeFID
 Session("FID") = Session("FID") + 1
 GenerateFID = Session("FID")
End Function

(iii) Registration of submitted forms

When the form is successfully submitted, it registers its unique identity in the Dictionary object:

Sub RegisterFID()
 Dim strFID
 InitializeFID
 strFID = Request("FID")
 Session("FIDlist").Add strFID, now()
End Sub

(iv) Check if the form is submitted repeatedly

Before you formally process a user-submitted form, you should check to see if its FID is registered in the Dictionary object. The following Checkfid () function completes this work, and returns False if it has been registered, otherwise returns true:

Function CheckFID()
 Dim strFID
 InitializeFID
 strFID = Request("FID")
 CheckFID = not Session("FIDlist").Exists(strFID)
End Function

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.