PDA

View Full Version : Need Help With Cookies!


John_Saunders
09-23-2002, 05:35 PM
I have a form on my website which uses cookies. I'm having big problems getting it to print a message for users who do not have cookies enabled. I've tried everything I can think of and I can only get it to post the form or the error message whether cookies are turned on or off.

Can somebody tell me what I need to change on this script so it will show the error if cookies are turned off and show the form if turned on?

header content

<%
count = Request.Cookies("count")

'### If the cookies has a NULL value write a value to it
if count = "" Then
Response.Cookies("count") = 0
Response.Cookies("count").Expires = Date + 1 '# wipes the cookie after a day
End If

'### Re-populate the count variable
count = Request.Cookies("count")

'### if it's still NULL then cookies must be off
if count = "" Then
%>

Your browser currently does not have cookies enabled. Please turn them on

<%
Else
count = CInt(count) + 1 '# use CInt as it will be a string from the cookie
Response.Cookies("count") = count
Response.Cookies("count").Expires = Date + 1
%>

<form>

form here

<%
If count < 5 Then
%>

<input type="submit" name="submit" value="submit"

<%
Else
%>

Please contact me for more info.

<%End If%>

</form>

<% End If %>

footer content


Any help would be greatly appreciated.

John

allida77
09-23-2002, 09:17 PM
What is this line of code for? :
If count < 5 Then

Take that whole if clause out and then it should only write out the form if count is not equal to " ". THe way it is now is that if count < 5 then print the form, which can be no cookies("") or whatever the current value of the cookie is less than 5.

John_Saunders
09-23-2002, 09:29 PM
The count < 5 is what detects how many times the visitor has submitted the form from the cookie. If they submitted it 5 times, the submit button will disappear and a message will come up that says to contact me for more information.

If I take this out then it will always show the submit button and it won't keep them from submitting it more than 5 times.

allida77
09-24-2002, 04:20 AM
Than I think that is the problem. If cookies can not be set on the client than "count" is <5 and will write out the form. Leave all your code and add this to the appropiate parts:



if count = "" Then
booCkie = false

Else

booCkie = true

----

If count < 5 AND booCkie = true Then

----