Web Wiz - Green Windows Web Hosting

  New Posts New Posts RSS Feed - Cookies to prevent multiple submissions
  FAQ FAQ  Forum Search   Events   Register Register  Login Login

Cookies to prevent multiple submissions

 Post Reply Post Reply
Author
Sparklebug View Drop Down
Newbie
Newbie
Avatar

Joined: 18 December 2001
Location: Australia
Status: Offline
Points: 38
Post Options Post Options   Thanks (0) Thanks(0)   Quote Sparklebug Quote  Post ReplyReply Direct Link To This Post Topic: Cookies to prevent multiple submissions
    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!

Back to Top
b_bonnett View Drop Down
Mod Builder Group
Mod Builder Group


Joined: 16 April 2003
Location: New Zealand
Status: Offline
Points: 275
Post Options Post Options   Thanks (0) Thanks(0)   Quote b_bonnett Quote  Post ReplyReply Direct Link To This Post 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, The Plane Gallery
Greetings From Christchurch
Back to Top
Sparklebug View Drop Down
Newbie
Newbie
Avatar

Joined: 18 December 2001
Location: Australia
Status: Offline
Points: 38
Post Options Post Options   Thanks (0) Thanks(0)   Quote Sparklebug Quote  Post ReplyReply Direct Link To This Post 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
%>

Back to Top
 Post Reply Post Reply

Forum Jump Forum Permissions View Drop Down

Forum Software by Web Wiz Forums® version 12.08
Copyright ©2001-2026 Web Wiz Ltd.


Become a Fan on Facebook Follow us on X Connect with us on LinkedIn Web Wiz Blogs
About Web Wiz | Contact Web Wiz | Terms & Conditions | Cookies | Privacy Notice

Web Wiz is the trading name of Web Wiz Ltd. Company registration No. 05977755. Registered in England and Wales.
Registered office: Web Wiz Ltd, Unit 18, The Glenmore Centre, Fancy Road, Poole, Dorset, BH12 4FB, UK.

Prices exclude VAT at 20% unless otherwise stated. VAT No. GB988999105 - $, € prices shown as a guideline only.

Copyright ©2001-2026 Web Wiz Ltd. All rights reserved.