SiteExperts.com Logo Home | Community | Developer's Paradise | Jobs
User Groups | Site Tools | Site Information | Search

Inside Technique : Multiple Form Posts : Our Solution

When we release our update early next year, all pages with forms on InsideDHTML are going to be ASP pages. Within the form, we include a hidden field that is dynamically populated with the current date and time. Using ASP and VBScript, we accomplish this by writing in the current date and time into a hidden TIMESTAMP field. In the following fragment, notice the <%=NOW()%> assignment to the timestamp value. This simple server script writes the current time into the page. In our case, it writes it as the value to the hidden TIMESTAMP field.

<FORM METHOD="POST">
  <INPUT TYPE=HIDDEN NAME=TIMESTAMP VALUE="<%=Now()%>">
  <INPUT TYPE=HIDDEN NAME=DOACTION VALUE="ADD">

  ... Remaining input items...
  <INPUT TYPE=SUBMIT VALUE="Submit Form">
</FORM>

We also include an DOACTION field that allows us to distinguish between multiple types of forms on the same page. When the user clicks on the submit button, the results are sent to the same page. This happens automatically since we omitted the form's ACTION attribute to specify an alternative destination URL.

At the top of this page, we include an ASP script that tests the timestamp field before accepting the submission. We use the value of the hidden DOACTION field to determine what to do with this form. The DOACTION field is our approach to reusing form submission code for different purposes.

<%
  ' Check if a new form submission by testing the timestamp
  If Request.Form("TIMESTAMP")<>Session("TIMESTAMP") and Request.Form("DOACTION")<>"" Then
    Session("TIMESTAMP") = Request.Form("TIMESTAMP")
    ' Process form submission and different DOACTION values
  End If
%>

At the beginning of each visit, each user gets their own unique Session object. On this Session object we store the timestamp of a particular user's last submission. On any form submission we perform the simple test comparing their last submission time with the time the current submission form was created. When they are not equal we assume its a new submission and process the results.

Discuss and Rate this Article

Page 1:Multiple Form Posts
Page 2:Our Solution