Tutorials to .com

Tutorials to .com » Asp » Xml » Applications in ASP How to limit time and again the same form was submitted! ! ! ! Good things

Applications in ASP How to limit time and again the same form was submitted! ! ! ! Good things

Print View , by: iSee ,Total views: 9 ,Word Count: 981 ,Date: Wed, 22 Apr 2009 Time: 10:18 AM

In the Internet every day we encounter countless forms, but also to see most of them do not restrict users to submit the same form several times. Sometimes the lack of such restrictions will have some unexpected results, such as e-mail subscription service to repeat or duplicate voting.

This article describes the application in the prevention of asp users several times during the current session in the same form to submit a simple method. It is mainly composed of four subroutines, in relatively simple applications, you simply place the code contains a direct reference to the document; for those more complex environment, we are given in the article, the final number of suggestions for improvement.

First, the basic process

Now we turn to discuss the four subroutines.

(A) initialization

Here we are in the Session object to save the two variables, of which:

⑴ each form a group called the FID corresponding to the unique identifier for the sole use of the value to a counter.

Whenever ⑵ successfully submitted a form to be in a Dictionary object to store its FID.

We use a dedicated process to initialize the above-mentioned data. While the various subroutine must be called after it, but in reality it is only every once during the conversation:

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


(B) form a unique identifier generated

The following function GenerateFID () used to generate the only sign the form. The first FID function value plus 1, and then return to it:

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


(C) The registration form has been submitted

When the form was submitted successfully, in the Dictionary object to register its unique identifier:

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


(D) check whether the repeated submission of form

In a formal deal with the user before submitting the form, it should be in the Dictionary object of the FID to check whether it has been registered. The following CheckFID () function used to complete this work, for example, have been registered, it return FALSE, otherwise return TRUE:

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


Second, how to use the

There are two places to use the above function, namely to generate a form with the results of treatment. Subroutine has been assumed that the four Forms.inc Add include file, the following code to determine the value according to FID to generate the form or forms to deal with the results of the process it describes ASP is suitable for most applications:

<% Option Explicit%>
<! - # Include file = "forms.inc" ->
<HTML>
<HEAD>
<TITLE> form to submit test </ TITLE>
</ HEAD
<BODY>
<%
If Request ( "FID") = "" Then
GenerateForm
Else
ProcessForm
End If
%>
</ BODY>
</ HTML>


Responsible for generating GenerateForm form, the form should contain a hidden FID, such as:

<%
Sub GenerateForm ()
%>
<Form action = "<% = Request.ServerVariables (" PATH_INFO ")%>" method = GET>
<Input type = hidden name = FID value = "<% = GenerateFID ()%>">
<Input type = text name = "param1" value = "">
<Input type = submit value = "OK">
</ Form>
<%
End Sub
%>


ProcessForm responsible for the content submitted through the form, but should be in handling the call before CheckFID () to check whether the current form has been submitted, the code categories such as:
<%
Sub ProcessForm ()
If CheckFID () Then
Response.Write "You entered is" & Request.QueryString ( "param1")
RegisterFID
Else
Response.Write "This form can only submit once!"
End If
End Sub
%>


Third, limitations and improvements

Above, we introduced during the current session limit in the same form was submitted by a method many times. In practical applications may need to be improved in many ways, such as:

⑴ ID in the registration form prior to check the legitimacy of the user input data, the data is not lawful user may press the "back" button to return to, in the revised submission of the same form again.

⑵ such restrictions on the form submission only effective during the current session. If such restrictions across multiple sessions, then they would have used to save Cookeis or database of relevant data.

⑶ this method is unsafe. It is only used to prevent misoperation, skilled users can not prevent intentionally submitted the same form several times.


Asp and XML related Articles


Can't Find What You're Looking For?


Rating: Not yet rated

Comments

No comments posted.