SitePoint Sponsor

User Tag List

Results 1 to 3 of 3

Threaded View

  1. #1
    SitePoint Member
    Join Date
    Jan 2007
    Posts
    2
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Need help! - Cookies on a Survey Site

    Hello.

    I am working on a survey.

    Part of my requirements are that no one fills in the survey more than once a month.

    When a user clicks complete, the page checks if there's a cookie from the site. If there is, they cannot submit (and an alert box pops up and says you already submitted). If not, the survey goes through, and they get redirected to the debriefing page.
    [The 'cookie check' has to be on the submit button, because all fields need to be filled - if not, there's an error, and they have to be able to correct the error and resubmit.]
    I have cookies set up so that when the user completes the survey (i.e., when they reach the "debriefing" page), they get a cookie.

    However, I can only set this up with a specific expiration date. How can I fix the code so that the cookie remains for 30 days from submission, no matter what date that is?

    Feel free to view the sources, and help me figure this out, please!!

    The survey (checking for the cookie) is:
    Code:
    <head>
    <script>
    	<!--
    	function AllowNoDups()
    	{
    	   var cookie_ls = document.cookie;
    	   if (cookie_ls.indexOf(document.location) > -1) 
    		{
    	      alert("You've already submitted your answers. Thank you for your interest!");
    	      return false;
    		}
    	  else
    		{
    		}; 
    	};
    	  //-->
    	</script>
    </head>
    
    ...
    <body>
    <form method="post" action="srvyfrm.php" OnSubmit="return AllowNoDups();">
    </body>
    The debriefing (setting up the cookie) is:
    Code:
    <head>
    <script>
    	<!--
    	function setCookie()
    	{
    
    	document.cookie = window.location.href + " from " + document.referrer + "; path=/; expires=Thu, 23-Aug-2012 00:00:01 GMT;";
    
    	};
    	  //-->
    </script>
    </head>
    Last edited by a06lp; Jan 9, 2007 at 11:56.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •