Print Page | Close Window

Cookies to prevent multiple submissions

Printed From: Web Wiz Forums
Category: General Discussion
Forum Name: Classic ASP Discussion
Forum Description: Discussion on Active Server Pages (Classic ASP).
URL: https://forums.webwiz.net/forum_posts.asp?TID=4976
Printed Date: 28 March 2026 at 4:08am
Software Version: Web Wiz Forums 12.08 - https://www.webwizforums.com


Topic: Cookies to prevent multiple submissions
Posted By: Sparklebug
Subject: Cookies to prevent multiple submissions
Date Posted: 12 August 2003 at 6:50pm

I'm running a basic survey using the code below followed by a form:

<%
If Request.Form("submit") = "Submit" Then
 ' Ensure there is some content
 If Len(Trim(Request.Form("Q1")) & Trim(Request.Form("Q2")) & Trim(Request.Form("Q3")) & Trim(Request.Form("Q4")) & Trim(Request.Form("Q5")) & Trim(Request.Form("Q6"))) > 0 Then
  set cn=server.createobject("adodb.connection")
  strConnect = "DRIVER={Microsoft Access Driver (*.mdb)};DBQ=" & Server.MapPath("/dbase/poll/CapitalPunishment.mdb")
  cn.open(strConnect)
  Set rs = Server.CreateObject("ADODB.RecordSet")
  strSQL = "SELECT * FROM Results"
  rs.Open strSQL,cn,3,3
  rs.AddNew
  rs("Question1") = Request.Form("Q1")
  rs("Question2") = Request.Form("Q2")
  rs("Question3") = Request.Form("Q3")
  rs("Question4") = Request.Form("Q4")
  rs("Question5") = Request.Form("Q5")
  rs("Question6") = Request.Form("Q6")
  rs.Update
  rs.Close
  cn.Close
  Set cn = Nothing
  mode = "thankyou"
 End If
End If
%>

I'd like to be able to set a cookie upon 'submit' of the form which will be checked if the person returns to this page.  If they have the cookie (meaning they've submitted their response already) they should then see the 'thank you' version of the page rather than the form.  What is the easiest way to do this?

Thanks!



-------------
bug x



Replies:
Posted By: b_bonnett
Date Posted: 12 August 2003 at 10:27pm

Try adding the code in red in:

If Request.Form("submit") = "Submit" And Request.Cookies("Form")("Submitted") <> 1 Then

...

  mode = "thankyou"
  Response.Cookies("Form")("Submitted") = 1
 End If
End If

Hope this helps,
Blair



-------------
Webmaster, http://www.planegallery.net/ - The Plane Gallery
Greetings From Christchurch


Posted By: Sparklebug
Date Posted: 14 August 2003 at 9:20pm

Thanks Blair - it certainly gave me enough of a clue to work it out.  Just so you know, this is how I ended up getting it to do what I wanted:

<%
IF Request.Cookies("cp_submitted")="yes" Then
mode = "thankyou"
End If
If Request.Form("submit") = "Submit" Then
 ' Ensure there is some content
 If Len(Trim(Request.Form("Q1")) & Trim(Request.Form("Q2")) & Trim(Request.Form("Q3")) & Trim(Request.Form("Q4")) & Trim(Request.Form("Q5")) & Trim(Request.Form("Q6"))) > 0 Then
  set cn=server.createobject("adodb.connection")
  strConnect = "DRIVER={Microsoft Access Driver (*.mdb)};DBQ=" & Server.MapPath("/dbase/poll/CapitalPunishment.mdb")
  cn.open(strConnect)
  Set rs = Server.CreateObject("ADODB.RecordSet")
  strSQL = "SELECT * FROM Results"
  rs.Open strSQL,cn,3,3
  rs.AddNew
  rs("Question1") = Request.Form("Q1")
  rs("Question2") = Request.Form("Q2")
  rs("Question3") = Request.Form("Q3")
  rs("Question4") = Request.Form("Q4")
  rs("Question5") = Request.Form("Q5")
  rs("Question6") = Request.Form("Q6")
  Response.Cookies("cp_submitted")="yes"
  rs.Update
  rs.Close
  cn.Close
  Set cn = Nothing
  mode = "thankyou"
 End If
End If
%>



-------------
bug x



Print Page | Close Window

Forum Software by Web Wiz Forums® version 12.08 - https://www.webwizforums.com
Copyright ©2001-2026 Web Wiz Ltd. - https://www.webwiz.net