What should happen is the form fields get validated, a cookie is set with email address as the unique id, then its either sent to a confirmation page or an error page stating the form has already filled out.Code:<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <meta content="en-us" http-equiv="Content-Language" > <script language="JavaScript" type="text/javascript"> <!-- Begin function resetform() { document.forms[0].elements[1]==""; } function submitForms() { if (isEmail() && isFname() && isLname() && isAddress() && isCity() && isState() && isZip()) if (confirm("\n Press submit to enter your information")) { alert("\nYour submission will now be sent!"); return true; } else { alert("\n You have chosen to abort the submission."); return false } else return false; } function isEmail() { if (document.forms[0].elements[1].value == "") { alert ("\n The E-Mail field is blank. \n\n Please enter your E-Mail address.") document.forms[0].elements[1].focus(); return false; } if (document.forms[0].elements[1].value.indexOf ('@',0) == -1 || document.forms[0].elements[1].value.indexOf ('.',0) == -1) { alert ("\n The E-Mail field requires a \"@\" and a \".\"be used. \n\nPlease re-enter your E-Mail address.") document.forms[0].elements[1].select(); document.forms[0].elements[1].focus(); return false; } return true; } function isFname() { if (document.forms[0].elements[2].value == "") { alert ("\n The First Name field is blank. \n\n Please enter your first name.") document.forms[0].elements[2].focus(); return false; } return true; } function isLname() { if (document.forms[0].elements[3].value == "") { alert ("\n The Last Name field is blank. \n\nPlease enter your last name.") document.forms[0].elements[3].focus(); return false; } return true; } function isAddress() { if (document.forms[0].elements[4].value == "") { alert ("\n The Address field is blank. \n\nPlease enter your address.") document.forms[0].elements[4].focus(); return false; } return true; } function isCity() { if (document.forms[0].elements[5].value == "") { alert ("\n The City field is blank. \n\nPlease enter your city.") document.forms[0].elements[5].focus(); return false; } return true; } function isState() { if (document.forms[0].elements[6].value == "") { alert ("\n The state field is blank.\n\nPlease enter your state.") document.forms[0].elements[6].focus(); return false; } return true; } function isZip() { if (document.forms[0].elements[7].value == "") { alert ("\n The Zip code field is blank. \n\nPlease enter your Zip code.") document.forms[0].elements[7].focus(); return false; } } //acts as flag for redirecting page var count=0; //function to check if the form has been filled by same person, by matching the e-mail function validate(forms) { //number of days for which the cookie is valid var days=99; var obj=isEmail; var expires = new Date (); expires.setTime(expires.getTime() + days * (24 * 60 * 60 * 1000)); if(obj.value==readCookie()) { alert("Submission not allowed, this person has already filled form previously.The e-mail address is same!!"); count=0; } else { SetCookie(obj.value,expires); //alert(readCookie()); count++; } } function eraseCookie(name) { SetCookie( "", -1); } //function for reading cookie function ReadCookie() { var ca = document.cookie.split(';'); var nameEQ = "EmailSubmission" + "="; for(var i=0; i < ca.length; i++) { var c = ca[i]; while (c.charAt(0)==' ') c = c.substring(1, c.length); if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length, c.length); } return null; } //set the cookie function SetCookie(cookieData, expireDate) { document.cookie = "EmailSubmission" + "=" + escape(cookieData) + "; expires=" + expireDate.toGMTString(); } function GetCookie(name) { var arg = name + "="; var alen = arg.length; var clen = document.cookie.length; var i = 0; while (i < clen) { var j = i + alen; if (document.cookie.substring(i, j) == arg) return GetCookieVal (j); i = document.cookie.indexOf(" ", i) + 1; if (i == 0) break; } return null; } //this function checks flag and redirects accordingly function redirect() { if(!count) location.href = 'error.html'; else location.href = 'acknowledgement.html'; } return true; } // End --> </script> <title></title> <style type="text/css"> div.c4 {text-align: center} table.c3 {background-color: #FFFF66} span.c2 {font-family: courier} span.c1 {font-family: courier; font-size: 144%} .auto-style1 { margin-bottom: 118px; } .auto-style2 { margin-left: 0px; } </style> </head> <body style="background-color: #C0C0C0"> <div class="c4" style="height: 140px"> <img alt="" height="150" src="masthead.jpg" width="960"></div> <form enctype="text/plain" name="addform" method='post' action="acknowledgement.html" id="addform" onSubmit="return submitForms()" class="auto-style2" style="height: 316px; width: 1350px"> <table border="3" cellpadding="10" class="auto-style1" style="height: 56px; width: 318px;"> <tr> <td align="center" style="height: 167px; width: 1549px"><strong><span class="c1">Join the Kudler Fine Foods Mailing List!<table class="c3" cellspacing="0" cellpadding="2" style="border-style: solid; border-width: 3px; background-color: #FFFFCC; height: 191px; width: 277px;"> <tr valign="baseline"> <td><span class="c2">Email Address:</span></td> <td><input type="text" name="Email Address" size="38,1" maxlength="80"></td> </tr> <tr> <td><span class="c2">First Name:</span></td> <td><input type="text" name="First Name" size="38,1" maxlength="80"></td> </tr> <tr> <td><span class="c2">Last Name:</span></td> <td><input type="text" name="Last Name" size="38,1" maxlength="80"></td> </tr> <tr> <td><span class="c2">Address:</span></td> <td><input type="text" name="Address" size="38,1" maxlength="80"></td> </tr> <tr> <td><span class="c2">City:</span></td> <td><input type="text" name="City" size="38,1" maxlength="80"></td> </tr> <tr> <td><span class="c2">State:</span></td> <td><input type="text" name="State" size="10,1" maxlength="25"></td> </tr> <tr> <td><span class="c2">Zip Code:</span></td> <td><input type="text" name="Zip Code" size="10,1" maxlength="25"></td> </tr> <tr> <td style="height: 22px"></td> </tr> </table> </span></strong></td> </tr> </table> <div class="c4" style="width: 310px"><input type="submit" value=" Submit "> <input type="button" value=" Return " onclick="window.location='acknowledgement.html'"> <input type="reset" value="Reset Form" onclick="resetform()"></div> <input type="hidden" name="Form" value="Submit Sub"> <br> </form> </body> </html>


Reply With Quote

Bookmarks