Reply
Prevent Resubmitting the same form more than once
Old 07-15-2006, 06:08 PM Prevent Resubmitting the same form more than once
Average Talker

Posts: 25
Trades: 0
Hi All,
I have a form which when submitted will validate the fields and then add the record to a database.
If a mandatory field is not completed, there is an instruction to return to the form and complete the mandatory fields and then submit.
The problem I have is preventing the user from resubmitting the same form once it has been added to the database.
I cannot deactivate the submit button, because if they need to return to complete mandatory fields, the submit button is still required.
I have read the article "Programming Forms To Submit Only Once" from 15seconds.com and this looks exactly what I need......
To prevent the same form from being submitted more than once we must:
Initialize the data structures.
Create a mechanism to give each form a unique identification.
Find a way to store a list of already submitted forms.
When processing a form submit, we just have to check if its ID is on the list.

I am having problems when adding the recommended code to my form and my process form pages.
Is there a very simple way to achieve preventing the same form being submitted twice?
Thanks!
devine is offline
Reply With Quote
View Public Profile
 
 
When You Register, These Ads Go Away!
Old 07-15-2006, 09:04 PM Re: Prevent Resubmitting the same form more than once
ExpressoDan's Avatar
Ultra Talker

Posts: 317
Name: This Space for Rent
Location: Georgia
Trades: 0
Well logically the example is correct. YOU need to identify a unique field on your form. For example; a username, surname, phone number, email address... etc. Once you have identified this field, you perform a check on existing records in the table against the one currently in question before the insert command runs.

If it doesn't make sense, post what you have so far and someone will be able to help you troubleshoot it...
__________________
Daniel
"I think therefore I am, I think." <!-- George Carlin
ExpressoDan is offline
Reply With Quote
View Public Profile Visit ExpressoDan's homepage!
 
Old 07-16-2006, 08:19 AM Re: Prevent Resubmitting the same form more than once
Average Talker

Posts: 25
Trades: 0
It's quite lengthy code, so I will try to shorten to include the relevant parts.
This is forms.inc:
Code:
<%
Sub InitializeFID()
   If Not IsObject(Session("FIDList")) Then
      Set Session("FIDList")=Server.CreateObject("Scripting.Dictionary")
      Session("FID")=0
   End If
End Sub
%>
<%
Function CheckFID()
Dim strFID
   InitializeFID
   strFID = Request("FID")
   CheckFID = not Session("FIDlist").Exists(strFID)
End Function
%>
<%
Function GenerateFID()
   InitializeFID
   Session("FID") = Session("FID") + 1
   GenerateFID = Session("FID")
End Function
%>
<%
Sub RegisterFID()
Dim strFID
   InitializeFID
   strFID = Request("FID")
   Session("FIDlist").Add strFID, now()
End Sub
%>
This is the form - I have highligted in red the code that was added from 15seconds.com:
Code:
<%@ LANGUAGE="VBSCRIPT" %>
<%response.buffer=true%>
<!--#include file="forms.inc"-->
<script language="javascript">
function chkSubmit(){
document.ChangeControlForm.action="confirm5.asp";
}
function chkSave(){
document.ChangeControlForm.action="save.asp";
}
function chkUpload(){
document.ChangeControlForm.action="ToFileSystem.asp";
}
</script>
<script type="text/javascript">
    //<![CDATA[
    function toggleSubmit(sel)
    {
      var submit = document.getElementById('submit');
      var area = document.getElementById('jarea');
      submit.value = (sel.options[sel.selectedIndex].value=="yes") ? 'Submit Emergency Change' : 'Submit to Change Control';
      jarea.style.display = (submit.value == 'Submit Emergency Change') ? 'block' : 'none';
    }
    //]]>
   
</script>
<head>
<title>Change Control Form</title>
<SCRIPT LANGUAGE="JavaScript">
<!-- 
function printWindow(){
bV = parseInt(navigator.appVersion);
if (bV >= 4) window.print();
}
//-->
</script>
</head>
<center>
<h2>
<img src="images/deault_01.jpg"></h2>
<h2><font face="Sky InfoText Bd" color="#0388BB" size="6">
CHANGE CONTROL FORM</font></h2>
<%response.write session("userid")%>
<br><hr><br>
<%
If Request("FID") = "" Then
   GenerateForm
Else
   ProcessForm
End If
%>
<body>
<font color="#FF0000" face="Sky InfoText Bd">Fields marked * are mandatory and must be completed</font>
<form name="ChangeControlForm" method="Post">
<%
Sub GenerateForm()
%>
<form action="<%=Request.ServerVariables("PATH_INFO")%>" method="GET">
<input type=hidden name=FID value="<%=GenerateFID()%>">
<br><table width="590">
<tr><td width="199" bgcolor="#260063">
  <font color="#FFFFFF" face="Sky InfoText Bd">Change Originator: </font> </td>
<td width="17" align="center">&nbsp;</td>
<td width="360"><input type="text" name="Originator" size="50" value='<%response.write session("username")%>'></td></tr>
<tr><td width="199" bgcolor="#260063">
  <font color="#FFFFFF" face="Sky InfoText Bd">Change Originator's Email: </font> </td>
<td width="17" align="center">&nbsp;</td>
<td width="360"><input type="text" name="Originator_Email" size="50" value="<%response.write session("email")%>"></td></tr>
<tr><td width="199" bgcolor="#260063">
  <font color="#FFFFFF" face="Sky InfoText Bd">Benefits/Justification of Change: </font> </td>
<td width="17" align="center"><font color="#FF0000" face="Times New Roman">*</font></td>
<td width="360"><textarea name="Justification" rows="3" size="150" cols="38"></textarea></td></tr>
 <tr><td width="199" bgcolor="#260063">
  <font color="#FFFFFF" face="Sky InfoText Bd">Status: </font> </td>
<td width="17" align="center">&nbsp;</td>
<td width="360"><input type="text" name="Status" size="15" value="Pending" readonly></td></tr>
<tr><td width="199" bgcolor="#260063">
  <font color="#FFFFFF" face="Sky InfoText Bd">Multi-part Linked CCF: </font> </td>
<td width="17" align="center">&nbsp;</td>
<td width="360"><input type="text" name="Linked" size="15" title="If this is a mulit-part CCF, which is linked to another CCF, please enter the relating CCF number"></td></tr>
<tr>
  <td width="199" bgcolor="#260063">
  <font color="#FFFFFF" face="Sky InfoText Bd">Upload Attachment: </font> </td>
<td width="17" align="center">&nbsp;</td>
<td width="360"><input type="file" name="File1" size="20"><INPUT type="Submit" value="Upload" onClick="chkUpload();"></td>
</tr>
  </table>  
 
<center>
<table>
<tr>
<td>
<input type="submit" name="Submit2" value="Save Progress" onClick="chkSave();"> 
<input id="submit" type="submit" name="Submit" value="Submit to Change Control" onClick="chkSubmit();"> 
</table>
</form>
</body><%
End Sub
%><br>
And this is the code that processes the form results:

Code:
<%Option Explicit%>
<!--#include file="forms.inc"-->
<p align="center">
<CENTER><H2>
<h2><img src="images/deault_01.jpg"></h2>
 

<% IF Request.Form("Summary") <> "" AND Request.Form("Area") <> "" AND Request.Form("Justification") <> "" AND Request.Form("Summary") <> "" AND Request.Form("Implementer") <> "" AND Request.Form("StartDate") <> "" AND Request.Form("Start") <> "" AND Request.Form("Finish") <> "" AND Request.Form("Details") <> "" AND Request.Form("Rep") <> "" THEN 
Sub ProcessForm()
   If CheckFID() Then 
   RegisterFID
set conn=Server.CreateObject("ADODB.Connection")
conn.Provider="Microsoft.Jet.OLEDB.4.0"
conn.Open "c:/inetpub/wwwroot/change control.mdb"
set rs=Server.CreateObject("ADODB.recordset")
rs.Open "tblform", conn, 2, 2
RS.AddNew
RS("Submitted") = Date()
RS("Type") = Request.Form("Type")
RS("Emergency") = Request.Form("Emergency")
RS("Summary") = Request.Form("Summary")
RS("Area") = Request.Form("Area")
RS("Component") = Request.Form("Componenet")
RS("Service") = Request.Form("Service")
RS("Originator") = Request.Form("Originator")
RS("Originator_Email") = Request.Form("Originator_Email")
RS("Justification") = Request.Form("Justification")
RS("Risks") = Request.Form("Risks")
RS("Implementer") = Request.Form("Implementer")
RS("Email") = Request.Form("Email")
RS("StartDate") = Request.Form("StartDate")
RS("EndDate") = Request.Form("EndDate")
RS("Email") = Request.Form("Email")
RS("Start") = Request.Form("Start")
RS("Finish") = Request.Form("Finish")
RS("Outage") = Request.Form("Outage")
RS("Details") = Request.Form("Details")
RS("Backout") = Request.Form("Backout")
RS("Comments") = Request.Form("Comments")
RS("Rep") = Request.Form("Rep")
RS("Status") = Request.Form("Status")
RS("Linked") = Request.Form("Linked")
RS("Saved") = ""
RS.Update
idOfAddedRecord = RS("CCF")
RS.Close
Set RS = Nothing
%> 
<font face="Sky InfoText Bd" color="#0388BB">Change Control Form <% = idOfAddedRecord %> 
has been submitted.
</font></H2>
<H2>
<font face="Sky InfoText Bd" color="#0388BB">Please quote this change number in 
all relating communication
</font></H2>
<br>
</p>
</font>
  <% Else
      Response.Write "This form can only be submitted once!"
   End If
End Sub %>
<% CONN.Close
Set CONN = Nothing
%>
<% ELSE
Response.Write "<p>Please click back on your browser and complete the following mandatory fields:</p>"
 If Request.Form("Summary") = "" THEN
 Response.Write "<b>• Summary</b><br>"
 End If
 If Request.Form("Area") = "" THEN
 Response.Write "<b>• Area of Impact</b><br>"
 End If
 If Request.Form("Justification") = "" THEN
 Response.Write "<b>• Benefits/Justification for change</b><br>"
 End If
 If Request.Form("Implementer") = "" THEN
 Response.Write "<b>• Implementer</b><br>"
 End If
 If Request.Form("StartDate") = "" THEN
 Response.Write "<b>• Start Date</b><br>"
 End If
 If Request.Form("Start") = "" THEN
 Response.Write "<b>• Proposed Start Time</b><br>"
 End If
 If Request.Form("Finish") = "" THEN
 Response.Write "<b>• Proposed End Time</b><br>"
 End If
 If Request.Form("Details") = "" THEN
 Response.Write "<b>• Details of Change/Method Statement</b><br>"
 End If
 If Request.Form("Rep") = "" THEN
 Response.Write "<b>• DTVPCMB Representative</b><br>"
 End If
End If %>
I'm not sure if the GET method on the form conflicts with the POST method on the form????
And I'm also not sure if I have added the 15seconds.com code in the correct places.
The error message that I am receiving is:
Microsoft VBScript runtime (0x800A000D)
Type mismatch: 'ProcessForm'
/changecontrolformonce.asp, line 53

This liine relates to:
<%
If Request("FID") = "" Then
GenerateForm
Else
ProcessForm
End If
%>
on the form.
It's a challenge! Any ideas?
devine is offline
Reply With Quote
View Public Profile
 
Old 07-16-2006, 01:01 PM Re: Prevent Resubmitting the same form more than once
ADAM Web Design's Avatar
Canadastaninianite

Posts: 5,942
Name: Adam for web page design, not program
Location: Toronto, Ontario, Canada
Trades: 0
You can't have a subprocedure inside of an if condition like that. You can call one inside of an if condition, but you can't actually declare one.
Code:
<% IF Request.Form("Summary") <> "" AND Request.Form("Area") <> "" AND Request.Form("Justification") <> "" AND Request.Form("Summary") <> "" AND Request.Form("Implementer") <> "" AND Request.Form("StartDate") <> "" AND Request.Form("Start") <> "" AND Request.Form("Finish") <> "" AND Request.Form("Details") <> "" AND Request.Form("Rep") <> "" THEN 
Sub ProcessForm()
   If CheckFID() Then 


It's this section here that's causing your trouble. To make your code simpler, move all of your subs up to the top of the page and then use all of your programming logic at the bottom.
ADAM Web Design is offline
Reply With Quote
View Public Profile Visit ADAM Web Design's homepage!
 
Old 07-21-2006, 06:34 AM Re: Prevent Resubmitting the same form more than once
Average Talker

Posts: 25
Trades: 0
OK, I've decided to take a completely different approach as I have to allow the users to be re-directed back to the form in case they have omitted mandatory fields.
What I have decided to do instead is check 8 fields against all records submitted for the current date. If all 8 fields have identical information already in the database to the form that is being submitted, the user will be notified "Error. This form already exists"

I have read up over the last 3 days, code that will allow me to check against the 8 fields before processing the form as normal.

I seem to be messing up my code as I go along!
Any ideas where I'm going wrong with this code:


Code:
 
<%DIM db, duprs, strSqlDim strsubmit, strSummary, strArea, strOriginator, strComponent, strService, strJustification, strImplementer, strEndD, StrStart, strEnd, strDetailsDIM strEmail, strOriginEmail, StrRep, strStartDate, strCCF, strBody'-- Get data from the form fieldsstrSubmit = Date()strSummary = Request.Form("Summary")strArea = Request.Form("Area")strOriginator = Request.Form("Originator")strComponent = Request.Form("Component")strService = Request.Form("Service")strJustification = Request.Form("Justification")strImplementer = Request.Form("Implementer")strStartDate = Request.Form("StartDate")strEndD = Request.Form("EndDate")strStart = Request.Form("Start")strEnd = Request.Form("End")strDetails = Request.Form("Details")strEmail=Request.Form("Email")strOriginEmail=Request.Form("Originator_Email")strRep=Request.Form("Rep")strRisk=Request.Form("Risks")strCCF=idOfAddedRecordstrBody="<font size=3 face=Helvetica Neue color=#0388BB>" & "<strong>" & "CCF " & strCCF & " has been submitted by " & strOriginator & "<br>" & "<br>" strBody=strBody & "<font size=2 face=Helvetica Neue color=#260063>" & "<strong>"& "Start Date: " & strStartDate & "<br>" strBody=strBody & "Start Time: " & strStart & "<br>" strBody=strBody & "Risk: " & strRisk & "<br>" strBody=strBody & "Change Summary: " & strSummary & "<br>" strBody=strBody & "Implementer: " & strImplementer & "<br>" & "<br>" & "<br>" strBody=strBody & "<font size=3 face=Helvetica Neue color=#0388BB>" & "<strong>" & "Click here to view full details " & "<a href=http://127.0.0.1/view.asp?qryid="& StrCCF & ">"& strCCF & "</a>"' Check if form has previously been submittedset dupconn=Server.CreateObject("ADODB.Connection")dupconn.Provider="Microsoft.Jet.OLEDB.4.0"dupconn.Open "c:/inetpub/wwwroot/change control.mdb"strSQL = "SELECT tblform.* FROM tblform WHERE tblform.submitted = '" & strSubmit & "' AND tblform.Summary = '" & strSummary & "' AND tblform.area = '" & strArea & "' AND tblform.Originator = '" & strOriginator & "' AND tblform.component = '" & strComponent & "' AND tblform.Service = '" & strService & "' AND tblform.justification = '" & strJustification & "' AND tblform.Implementer = '" & strImplementer & "' AND tblform.startdate = '" & strStartD & "' AND tblform.EndDate = '" & strEndD & "' AND tblform.start = '" & strStart & "' AND tblform.End = '" & strEnd & "' AND tblform.Details = '" & strDetails & "'" Set dupRS = Server.CreateObject("ADODB.recordset")dupRS.Open "tblform", conn, 2, 2IF NOT RS.EOF THEN%> <font face="Arial" size="3" color="#0388BB">ERROR! This form already exists! </font>"<%END IF%><%RS.CloseSet RS = Nothing %><% IF Request.Form("Summary") <> "" AND Request.Form("Area") <> "" AND Request.Form("Justification") <> "" AND Request.Form("Summary") <> "" AND Request.Form("Implementer") <> "" AND Request.Form("StartDate") <> "" AND Request.Form("Start") <> "" AND Request.Form("Finish") <> "" AND Request.Form("Details") <> "" AND Request.Form("Rep") <> "" THEN set conn=Server.CreateObject("ADODB.Connection")conn.Provider="Microsoft.Jet.OLEDB.4.0"conn.Open "c:/inetpub/wwwroot/change control.mdb"set rs=Server.CreateObject("ADODB.recordset")rs.Open "tblform", conn, 2, 2RS.AddNewRS("Submitted") = Date()RS("Type") = Request.Form("Type")RS("Emergency") = Request.Form("Emergency")RS("Summary") = Request.Form("Summary")RS("Area") = Request.Form("Area")RS("Component") = Request.Form("Component")RS("Service") = Request.Form("Service")RS("Originator") = Request.Form("Originator")RS("Originator_Email") = Request.Form("Originator_Email")RS("Justification") = Request.Form("Justification")RS("Risks") = Request.Form("Risks")RS("Implementer") = Request.Form("Implementer")RS("Email") = Request.Form("Email")RS("StartDate") = Request.Form("StartDate")RS("EndDate") = Request.Form("EndDate")RS("Email") = Request.Form("Email")RS("Start") = Request.Form("Start")RS("Finish") = Request.Form("Finish")RS("Outage") = Request.Form("Outage")RS("Details") = Request.Form("Details")RS("Backout") = Request.Form("Backout")RS("Comments") = Request.Form("Comments")RS("Rep") = Request.Form("Rep")RS("Status") = Request.Form("Status")RS("Linked") = Request.Form("Linked")RS("Saved") = ""RS.UpdateidOfAddedRecord = RS("CCF")RS.CloseSet RS = Nothing%> <font face="Arial" color="#0388BB">Change Control Form <% = idOfAddedRecord %> has been submitted.</font></H2>
There are extra strings defined at the top of the code as there is an email function at the end of the code and also additional code which specifies missing mandatory fields, so please note this is not the complete code.
I have highlighted in red what I am trying to achieve, but really need some guidance!
Thanks in advance guys!

Last edited by devine; 07-21-2006 at 06:35 AM..
devine is offline
Reply With Quote
View Public Profile
 
Old 07-21-2006, 02:06 PM Re: Prevent Resubmitting the same form more than once
Ultra Talker

Posts: 256
Location: Auckland, New Zealand
Trades: 0
Do clientside checking and don't submit the form if that fails. Check my recent post for a Simple HTML form @ http://www.webmaster-talk.com/264820-post4.html. if onsubmit returns false, the form won't continue, if it returns true, the submit will be disabled and it'll do the action, which for this person was a mailto:

If you don't want to do clientside, then don't rely on sending them back, process the form from the same page, or redo the form in your processing script and just re-enter the information you received back into it and unset the information that was not correct, and maybe change the appearance, or do something they'll show them where to fix the problem, you could control the submit button there, in fact you could have it disabled until all conditions are met before activating it. There's many ways you can achieve what you want.

Cheers,

MC
__________________
#------------------------------signature---------------------------------------------------------------------------------#
Quote:
I am well recognised for what I don't do than what I do. Chores are just one of those things.

Last edited by mastercomputers; 07-21-2006 at 02:14 PM..
mastercomputers is offline
Reply With Quote
View Public Profile Visit mastercomputers's homepage!
 
Old 07-22-2006, 12:32 AM Re: Prevent Resubmitting the same form more than once
Junior Talker

Posts: 1
Trades: 0
I have several scripts for sale. I am selling them for reasonable prices. If you are interested please see below. For more information and demos on the scripts please send an email to bestscriptz@yahoo.com.
  • Myspace Scripts
  • Youtube Scripts
  • Alibaba/B2B.com
  • Facebook Scripts
  • Auction Scripts
  • Web host billing & support
  • Job Script
  • Dating Script
  • Scriptlance Script
  • Myspace Support & Generator
  • Community Script
  • Classified Script
  • Auto Classified Script
  • Business Verification
  • Escrow
  • Homebased Business
  • Milliondollarhomepage Script
  • Auction Scripts
  • Smarterscripts

For more information and demos on the scripts please send an email to bestscriptz@yahoo.com. All prices are negotiable and we are very flexible.
cashyourcontent is offline
Reply With Quote
View Public Profile
 
Reply     « Reply to Prevent Resubmitting the same form more than once
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML

 


Page generated in 0.12169 seconds with 13 queries