Hi Everyone,
Well here I am again, I have my form code all set, thanks to PsychoCoder. I now have to add a cookie to the form so that once the form has been completed and submitted it will tell the user that they already submitted the form. I borrowed PsychoCoder's "cookie snippet" as a place to start, but I am not sure how to get the cookie to validate and return a notification page that I have written. I will post the form coed here:
CODE
<html>
<head>
<!--
Timothy Shannon
WEB406 - Week 4
Individual Assignment
Complete Change Request - #2
on Service Request - SR-kf-011
-->
<!--
Page title
-->
<title>Kudler Fine Foods Specials and Events Mailing List Registration Form</title>
<script type="text/javascript">
<!-- Define cookie -->
set_cookie("LoggedIn",true,10);
function set_cookie(fname, value, days)
{
if (days)
{
var date = new Date();
date.setTime(date.getTime() + (days*24*60*60*1000));
var expires = "; expires=" + date.toGMTString();
} else var expires = "";
var host = "your_domain.com";
var domain = "; domain=" + host;
document.cookie = fname + "=" + value + expires + domain + "; path=/";
}
get_cookie("LoggedIn");
function get_cookie(fname)
{
var EQ = fname + "=";
var ca = document.cookie.split(';');
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(EQ) == 0) return c.substring(EQ.length,c.length);
}
return null;
}
<!-- Form validation -->
function submitForm()
{
if (document.forms[0].fname.value == "" || document.forms[0].lname.value == "") {
window.alert("You must enter your first and last names.");
return false;
}
else
{
if (document.forms[0].address.value == "" && document.forms[0].email.value == "")
{
window.alert("You must enter either a mailing address or email address.");
return false;
}
else
{
return true;
}
}
}
</script>
</head>
<form name="request" id="request" action="FormProcessor.html"
onsubmit="return submitForm();"
onreset="return confirmReset();"
enctype="application/x-www-form-urlelncoded">
<table border="0" cellspacing="0" cellpadding="5" width="620" >
<thead style="font-family: times-new roman">
<!--
Header and logo
-->
<tr>
<td valign="top" width="180" rowspan="2">
<img src="Kudler.jpg" alt="kudler" width="375" height="200" >
</td>
<td style="font-size: 2.2em; color: black; font-weight: bold; font-style: italic"
valign="top" align="center" >
Kudler Fine Foods Specials and Events Mailing List Registration
</td>
</tr>
</thead>
<!-- Customer information header -->
<tr>
<td style="font-family: times-new roman; font-size: large; font-weight: bold"
colspan="2" width="100%">
Customer Information
</td>
</tr>
<tr>
<td style="font-family: times-new roman; color: red; font-size: small; font-style: italic"
colspan="2" width="100%">
* Required
** Either is required
</td>
</tr>
<tr>
<td colspan="2">
<hr style="color: red; background-color: red; height: 3" >
</td>
</tr>
<!-- Input fields -->
<tr>
<td valign="top" colspan="2">
<table>
<tr>
<td width="50"><label for="fname">First</label></td>
<td><input type="text" name="fname" id="fname" size="30" ><label style="color: red">*</label></td>
<td width="50"><label for ="lname">Last</label></td>
<td><input type="text" name="lname" id="lname" size="30" ><label style="color: red">*</label></td>
</tr>
<tr>
<td width="100"><label for ="address">Address</label></td>
<td><input type="text" name="address" id="address" size="60" ><label style="color: red">**</label></td>
</tr>
<tr>
<td><label for="phone">Phone</label></td>
<td><input type="text" name="phone" id="phone" size="12" >
</td>
</tr>
<tr>
<td><label for="email">Email Address</label></td>
<td><input type="text" name="email" id="email" size="40" ><label style="color: red">**</label></td>
</tr>
</table>
</td>
<tr>
<td valign="top">
<input type="checkbox" name="Purpose" id="mail" value="Mailing list" >
<label for="mail">Add me to your Mailing List</label><br >
</td>
</tr>
<tr>
<td colspan="2">
<hr style="color: red; background-color: red; height: 3" >
</td>
</tr>
<!--
Customer comments
-->
<tr>
<td width="100" valign="top">
<label for="comments">Comments</label>
</td>
<td valign="top">
<textarea name="comments" id="comments" rows="6" cols="40">
</textarea>
</td>
</tr>
<!-- Register/cancel buttons -->
<tr>
<td valign="top" colspan="2" align="center">
<input type="Submit" value="Register" >
<input type="reset" value="Cancel" >
</td>
</tr>
<!-- Company name and locations -->
<tr style="background-color: red">
<td colspan="2" align="center" valign="bottom">
<address style="font-family: times-new roman; font-size: 0.6em; font-style: normal; font-size: small; color: black">
Kudler Fine Foods ˇ Shopping the World for the Finest Foods ˇ La Jolla ˇ Del Mar ˇ Encinitas ˇ
</address>
</td>
</tr>
</table>
</form>
</html>
And I will post the notification page code here:
CODE
<html>
<head>
<title>Form Already Processed</title>
</head>
<body>
<script type="text/javascript">
document.write("<h1>Your information is already on file!</h1><h2>You have already registered for our list!</h2>");
var formData = location.search;
formData = formData.substring(1, formData.length);
while (formData.indexOf("+") != -1) {
formData = formData.replace("+", " ");
}
formData = unescape(formData);
var formArray = formData.split("&");
for (var i=0; i < formArray.length; ++i) {
document.writeln(formArray[i] + "<br />");
}
</script>
</body>
</html>
Thank you all again in advance for any help offered, I have received nothing but help here in the past and I've got to tell you it's a GREAT feeling having somewhere you can go for help and actually get answers.
Tim