I have created a contact form page on my website. It all works correctly but the thing I want to do is when there is an error in my form such as incorrect format for email address or missing field I want the error page to say 'Error. Please fill in all fields correctly and try again:' and below have the same form. So far I have done this, but the problem is the fields are all blank and the user would have to start again.
How can I remember the values from the previous page and have them pre-filled in on the error page?
This is the code for the contact form. (contact.php)
Code: Select all
<center><table><tr><td>
Please fill out all fields.<br><br>
<font size="2">
<form method="post" action="sendeail.php">
<!-- DO NOT change ANY of the php sections -->
<?php
$ipi = getenv("REMOTE_ADDR");
$httprefi = getenv ("HTTP_REFERER");
$httpagenti = getenv ("HTTP_USER_AGENT");
?>
<input type="hidden" name="ip" value="<?php echo $ipi ?>" />
<input type="hidden" name="httpref" value="<?php echo $httprefi ?>" />
<input type="hidden" name="httpagent" value="<?php echo $httpagenti ?>" />
Your Name: <br />
<input class="input" type="text" name="visitor" size="35" />
<br /><br>
Your Email:<br />
<input class="input" type="text" name="visitormail" size="35" />
<br /><br>
Reason for Contacting:<br />
<select class="input" name="attn" size="1" style="width: 200px;">
<option value=" General Question ">General Question</option>
<option value=" Re: Free Quote ">Re: Free Quote</option>
<option value=" Technical Support ">Technical Support</option>
<option value=" Other ">Other</option>
</select>
<br /><br />
Message:
<br />
<textarea class="input" name="notes" rows="4" cols="40"></textarea>
<br /><br>
<input class="input" type="image" src="/images/btn_send.jpg" value="Send" />
</form>
</td></tr></table>Code: Select all
<?php
$visitor = $_POST['visitor'];
$visitormail = $_POST['visitormail'];
$notes = $_POST['notes'];
$attn = $_POST['attn'];
if (eregi('http:', $notes)) {
die ("Do NOT try that! ! ");
}
if(!$visitormail == "" && (!strstr($visitormail,"@") || !strstr($visitormail,".")))
{
header( 'Location: http://www.hiqmods.com/index.php?id=error' );
$badinput = header( 'Location: http://www.hiqmods.com/index.php?id=error' );
echo $badinput;
die (" ");
}
if(empty($visitor) || empty($visitormail) || empty($notes )) {
header( 'Location: http://www.hiqmods.com/index.php?id=error' );
die (" ");
}
$attn = $attn ;
$subject = $attn;
$notes = stripcslashes($notes);
$message = "$todayis From: $visitor\n
Email: $visitormail \n
Subject: $attn \n
Message: $notes \n
IP: $ip \n
Browser: $httpagent \n
";
$from = "From: contact@hiqmods.com\r\n";
mail("tstanniland@yahoo.com", $subject, $message, $from);
header('Location: index.php?id=sent');
?>Code: Select all
<font class="Error">Error. Please fill in all fields correctly and try again:<br><br>
<center><table><tr><td>
Please fill out all fields.<br><br>
<font size="2">
<form method="post" action="sendeail.php">
<!-- DO NOT change ANY of the php sections -->
<?php
$ipi = getenv("REMOTE_ADDR");
$httprefi = getenv ("HTTP_REFERER");
$httpagenti = getenv ("HTTP_USER_AGENT");
?>
<input type="hidden" name="ip" value="<?php echo $ipi ?>" />
<input type="hidden" name="httpref" value="<?php echo $httprefi ?>" />
<input type="hidden" name="httpagent" value="<?php echo $httpagenti ?>" />
Your Name: <br />
<input class="input" type="text" name="visitor" size="35" />
<br /><br>
Your Email:<br />
<input class="input" type="text" name="visitormail" size="35" />
<br /><br>
Reason for Contacting:<br />
<select class="input" name="attn" size="1" style="width: 200px;">
<option value=" General Question ">General Question</option>
<option value=" Re: Free Quote ">Re: Free Quote</option>
<option value=" Technical Support ">Technical Support</option>
<option value=" Other ">Other</option>
</select>
<br /><br />
Message:
<br />
<textarea class="input" name="notes" rows="4" cols="40"></textarea>
<br /><br>
<input class="input" type="image" src="/images/btn_send.jpg" value="Send" />
</form>
</td></tr></table>Tom.