Je ne cherche pas quelqu'un pour faire mon travail pour moi ... J'ai besoin d'aide/conseil.Comment utiliser un cookie pour détecter si l'utilisateur a déjà envoyé le formulaire?
J'ai besoin de:
Modifier la page de formulaire afin que lorsque la fonction JavaScript a vérifié que tous les champs obligatoires ont été remplies, un cookie est ajouté à l'ordinateur de l'utilisateur. Si le même utilisateur tente de remplir le formulaire une deuxième fois, l'utilisateur sera redirigé vers une page HTML distincte pour l'informer qu'il a déjà envoyé le formulaire.
Qu'est-ce que je fais mal?
C'est ma forme:
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Request Form</title>
<meta name="Description" content="This webpage is for Customer Demographics" />
<meta name="Keywords" content="Rhonda , email, " />
<meta name="author" content="Rhonda " />
<meta name="copyright" content="Copyright 2010 Rhonda , All Rights Reserved" />
<meta name="robots" content="all" />
<meta name="revisit-after" content="15 days" />
<meta name="rating" content="safe for kids" />
<script>
<!-- page to go to if cookie -->
go_to = "Submit.html";
num_days = -1;
function ged(noDays){
var today = new Date();
var expr = new Date(today.getTime() + noDays*24*60*60*1000);
return expr.toGMTString();
}
function readCookie(cookieName){
var start = document.cookie.indexOf(cookieName);
if (start == -1){
document.cookie = "seenit=yes; expires=" + ged(num_days);
} else {
window.location = go_to;
}
}
readCookie("seenit");
</script>
<script type="text/javascript" >
function verify() {
var themessage = "You are required to complete the following fields: ";
if (document.form.first.value=="") {
themessage = themessage + " - First Name";
}
if (document.form.middle.value=="") {
themessage = themessage + " - Middle Initial";
}
if (document.form.last.value=="") {
themessage = themessage + " - Last Name";
}
if (document.form.street.value=="") {
themessage = themessage + " - Street";
}
if (document.form.city.value=="") {
themessage = themessage + " - City";
}
if (document.form.state.value=="") {
themessage = themessage + " - State";
}
if (document.form.zip.value=="") {
themessage = themessage + " - Zip Code";
}
if (document.form.email.value=="") {
themessage = themessage + " - E-mail";
}
if (document.form.areacode.value=="") {
themessage = themessage + " - Area Code";
}
if (document.form.telephone.value=="") {
themessage = themessage + " - Telephone";
}
if (themessage == "You are required to complete the following fields: ") {
document.form.submit();
}
else {
alert(themessage);
return false;
}
}
</script>
</head>
<body>
<body style="background-color:lightsteelblue">
<h1>
Welcome customer.
<br />
<br />
<br />
Please enter the following details in order
to be added to our preferred customer mailing list:
<br />
<br />
<br />
</h1>
<!--This code builds the form -->
<form name=form method="post" action="">
<!--Personal information: -->
<form action="">
<fieldset>
<legend>Personal Information:</legend>
<br /><br />
First Name:<input type=text name="first" size="20"> <br /><br /><br />
Middle Initial:<input type=text name="middle" size="3"><br /><br /><br />
Last Name:<input type=text name="last" size="20"> <br /><br />
<br />
</fieldset>
<br /><br />
<form action="">
<fieldset>
<legend>Address:</legend>
<!--Address: -->
Street: <input type=text name="street" size="30"><br /><br />
City: <input type=text name="city" size="30"><br/><br />
State:<input type=text name="state" size="2"><br/><br />
Zip Code: <input type=text name="zip" size="7"><br /><br />
<br />
</fieldset>
<br /><br />
<!--Contact Information: -->
<form action="">
<fieldset>
<legend>Contact Information:</legend>
Email Address:<input type=text name="email" size="25" />
<br /><br />
Area Code:<input type=text name="areacode" size="3" /><br /><br />
Telephone Number:<input type=text name="telephone" size="7" />
<br />
<br />
</fieldset>
<br /><br /><br />
<!--NOTES
This part was not mandantory. I was just trying some of the extra ways of adding input that the book discussed-->
<form action="">
<fieldset>
<legend>Extra Credit:</legend>
<p>
Gender:
<br />
<input type="radio" name="sex" value="male" /> Male<br />
<input type="radio" name="sex" value="female" /> Female
</p>
<p>
How did you hear about us?
<br />
<input type="checkbox" name="Friend" value="Friend" /> From a friend
<br />
<input type="checkbox" name="Advertisement" value="Advertisement" /> Store Advertisement
<br />
<input type="checkbox" name="Online" value="Online" /> From Online
<br />
<input type="checkbox" name="Other" value="Other" /> Other
<br />
</p>
<p>
How do you wish to be contacted?
<br />
<form action="">
<select name="contact">
<option value="telephone">Telephone</option>
<option value="E-mail">E-mail</option>
<option value="Snail-mail">Snail-mail</option>
</select>
<br />
<br />
</fieldset>
</p>
</form>
<form action="" onSubmit="return verify()" method="post">
<input type="submit" name="submit" value="Submit">
<input type=reset value="Clear Form"><br>
</form>
<!--Back to top -->
<p><a href="#top">Back to Top</a></p>
</body>
</html>
Ceci est une question de programmation. Déplacement vers StackOverflow. –
@Tokk: ["La balise homework, comme les autres balises" meta ", est maintenant déconseillée,"] (http://meta.stackoverflow.com/q/10812) mais, @ rh0nda, s'il vous plaît (comme toujours) continuez de suivre [les directives générales] (http://tinyurl.com/so-hints), indiquez toutes les restrictions spéciales, montrez ce que vous avez essayé jusqu'ici et posez des questions sur ce qui vous trouble particulièrement. –