...

View Full Version : Redirect in javascript, but save the form data that you submitted?



Andy92
12-19-2006, 11:04 PM
Hi there,

I have 2 files. Index.php and send.php.

In the index.php i have in the middle...



<?php
$sent = $_GET['sent'];
if ($sent == 1) { echo "<div class='text_bold'>Thank you $name for contacting Will. I will reply to your email asap!</div><br />";
} else {
echo "";
}
$error = $_GET['error'];
if ($error == 1) { echo "<span class='n_error'>You have not entered a name!</span><br /><br />";
} else if ($error == 2) { echo "<span class='n_error'>You have not entered a email address!</span><br /><br />";
} else if ($error == 3) { echo "<span class='n_error'>You have not entered a subject!</span><br /><br />";
} else if ($error == 4) { echo "<span class='n_error'>You have not entered a message!</span><br /><br />";
} else {
echo "";
}
?>
<div class="large_col">
<div class="large_top_header">Contact Will Form:</div>
<div class="large_bottom_text">
<form action="/contact/will/send.php" method="post" name="will" id="will">
<table width="100%">
<tr>
<td><div><div class="text_bold">Name: <span class="text_link_colour">*</span></div></div></td>
<td width="83%"><input name="name" type="text" id="name" style="width: 475px;" maxlength="100" /></td>
</tr>
<tr>
<td><div><div class="text_bold">Email: <span class="text_link_colour">*</span></div></div></td>
<td><input name="email" type="text" id="email" style="width: 475px;" maxlength="100" /></td>
</tr>
<tr>
<td><div><div class="text_bold">Subject: <span class="text_link_colour">*</span></div></div></td>
<td><input name="subject" type="text" id="subject" style="width: 475px;" maxlength="200" /></td>
</tr>
<tr>
<td width="17%" height="17"><div><div class="text_bold">Message: <span class="text_link_colour">*</span></div></div> </td>
<td rowspan="2"><textarea name="message" rows="10" id="message" style="width: 475px;"></textarea></td>
</tr>
<tr>
<td height="50">&nbsp;</td>
</tr>
<tr>
<td height="17" colspan="2"><span class="text_link_colour">*</span> = Required Field</td>
</tr>
<tr>
<td height="23" colspan="2"><div align="center">
<input name="Send" type="submit" id="Send" value="Send!" />
</div></td>
</tr>
</table>
</form>
</div>
</div>


Then in the send.php page i have the form processing...



<?php
@extract($_POST);
$name = stripslashes($name);
$email = stripslashes($email);
$subject = stripslashes($subject);
$message = stripslashes($message);
if (!$name) {echo
"<script language='JavaScript' type='text/javascript'>
<!--
window.location.href = '/contact/will/index.php?error=1'
//-->
</script>";
} else {
if (!$email) {echo
"<script language='JavaScript' type='text/javascript'>
<!--
window.location.href = '/contact/will/index.php?error=2'
//-->
</script>";
} else {
if (!$subject) {echo
"<script language='JavaScript' type='text/javascript'>
<!--
window.location.href = '/contact/will/index.php?error=3'
//-->
</script>";
} else {
if (!$message) {echo
"<script language='JavaScript' type='text/javascript'>
<!--
window.location.href = '/contact/will/index.php?error=4'
//-->
</script>";
} else {

mail("will@allsortshop.com",$subject,$message,"From: $name <$email>");
echo "<script language='JavaScript' type='text/javascript'>
<!--
window.location.href = '/contact/will/index.php?sent=1'
//-->
</script>";
}
}
}
}
?>


Basically, if you forget to type in a subject on the form, it wil redirect you to http://www.allsortshop.com/contact/will/index.php?error=3

Then the error message will show up. But the form data would be lost?

If it would have just displayed an error message on the send.php page and then if you would have clicked back on your mouse all the form data would be there.

So my question is, is there anyway to save the form data only for about 10 minutes in a cookie or something so that when they click submitt and if there is an error message and it redirects them, the form data would still be there? (but the data would only be saved in a cookie of something for a short period of time)?

Is there any way to do this with javascript? :confused:

nikkiH
12-20-2006, 10:47 PM
That's a rather unique way to validate a form.
Why did you choose this design?



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum