View Full Version : I need help with my form checking
unregistered
12-30-2002, 06:16 AM
Ok. I'm really bad with asp, and i'm wondering if someone could help me make a script that will put a cookie into a person's computer that expires in say, a minute. Now this cookie is planted when he/she submits my form, and the form wont let them submit again until the cookie has expired (1 minute). Its on an emailing form, and i don't want humungo spam from people who just click submit, go back and hit submit again.
Any help would be greatlky appreciated.
--The amazing Boo
Oh! just so you know the page is at http://clix.to/bg2 its also under construction.
miranda
12-30-2002, 07:17 AM
why not use clientside javascript to disable the submit button once the form has been sent in ? If you do this along with validation making them fill out the form each time no one will bother trying to reclick. Here is a link for such
http://javascript.internet.com/forms/disable-submit.html
if you want to set a cookie in asp to expire in two seconds then do so like this. (Written in VBScript)
<%
Response.Cookies("foobar").Expires = dateadd("s",2,now)
%>
If you can use asp.net read this
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/frlrfSystemWebUIHtmlControlsHtmlControlClassDisabledTopic.asp
whammy
12-30-2002, 11:56 PM
Or a pretty simple solution, just set a session variable once the form is submitted...
Session("submitted") = "1"
Then check to make sure Session("submitted") <> "1" before processing the email... i.e.:
If Session("submitted") <> "1" Then
'Process your email here
Else
'It was already submitted
End If
If you want to do it with a cookie, it's just as easy, too:
Response.Cookies("submitted") = "1"
Response.Cookies("submitted").Expires = DateAdd("s", 60, Now())
Then check to make sure Request.Cookies("submitted") <> "1" before processing the email... i.e.:
If Request.Cookies("submitted") <> "1" Then
'Process your email here
Else
'The cookie was set less than a minute ago
End If
:)
P.S. Oops! Didn't notice you already gave him the DateAdd() solution, Miranda. ;)
P.P.S. I had read some posts about the DateAdd() function not working with cookie expirations, so just to be sure I tested the code above and it works perfectly. Re-reading the posts in question, it's obvious the user was using a variable for one of the DateAdd() parameters which apparently didn't have a value. Go figure. :D
vBulletin® v3.8.2, Copyright ©2000-2012, Jelsoft Enterprises Ltd.