form - problem with browser cache

liunx

Guest
i read somewhere that it's advisable to tell the browser not to cache a form in case the user ends up getting your last error page -- and this makes sense to me -- i would like the form to reset back to start whenever the user presses refresh or types the form address into the browser -- i have the form designed to redisplay correct fields if the user makes an error in one of the other fields so there shouldn't be any problems - however neither the refresh or 'go' buttons reset the form - how can i do this<br />
<br />
any help greatly appreciated<br />
bob<br />
<br />
what i'm working with at the moment is <br />
<html><br />
<head><br />
</head><br />
<body><br />
<br />
<?php <br />
// invalidate browser caching of this page<br />
header( "Expires: Mon, 20 Dec 1998 01:00:00 GMT" );<br />
header( "Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT" );<br />
header( "Cache-Control: no-cache, must-revalidate" );<br />
header( "Pragma: no-cache" );<br />
<br />
// Handle older versions of PHP<br />
if( ! isset( $_GET ) )$_GET = &$HTTP_GET_VARS;<br />
if( ! isset( $_POST ) )$_POST = &$HTTP_POST_VARS;<br />
if( ! isset( $_SERVER ) ) $_SERVER = &$HTTP_SERVER_VARS;<br />
<br />
// Add as many Names/ Departments -- e-mail addresses as you want here<br />
$eMail[] = array( 'Information', <!-- e --><a href="mailto:'[email protected]">'[email protected]</a><!-- e -->' );<br />
$eMail[] = array( 'TechSupport', <!-- e --><a href="mailto:'[email protected]">'[email protected]</a><!-- e -->' );<br />
$eMail[] = array( 'Billing Questions', <!-- e --><a href="mailto:'[email protected]">'[email protected]</a><!-- e -->' );<br />
<br />
<br />
// Original field values<br />
$nameOrigValue = "type your name";<br />
$emailOrigValue = "type your email";<br />
<br />
echo "<form method=\"post\" name=\"form\" ".((isset($_SERVER['PHP_SELF']))?'action="'.$_SERVER['PHP_SELF'].'"':'').">"<br />
?><br />
<br />
To:<select size="1" name="To"><br />
<br />
<?php <br />
foreach( $eMail as $k => $a )<br />
if( (isset($_GET["To"])) && ( $_GET["To"] == $k) )<br />
echo "<option value=\"$k\" selected>$a[0]</option>\n";<br />
else<br />
echo "<option value=\"$k\">$a[0]</option>\n";<br />
?><br />
</select><br /><br />
<br />
Name:<input type="text" id = "name" name="name" size="44" value= <br />
<?php echo ("\"" . ($_POST['name']=='' ? $nameOrigValue: $_POST['name']) ."\"" ); ?> <br />
onFocus = "this.value='';" <br />
/> <br />
<br /><br />
<br />
E-Mail:<input type="text" id = "EMail"name="EMail" size="44" value = <br />
<?php echo ("\"" . ($_POST['EMail']=='' ? $emailOrigValue: $_POST['EMail']) ."\"" ); ?> /><br />
<br /><br />
<br />
Subject:<br />
<input type="text" name="Subject" size="44"><br /><br />
<textarea rows="10" name="Body" cols="45"></textarea><br />
<br />
<input type="submit" name="sent" value="Send"><br /><br /><br />
</form><br />
<br />
<br />
<?php<br />
<br />
if ($sent) // validate & send when user submits<br />
{ <br />
<br />
// validate first<br />
<br />
$valid =true;<br />
if ( (empty( $name )) || ( ($name == $nameOrigValue ) ) )<br />
{<br />
$errmsg .= "enter your name ... <br />"; $valid = false;<br />
?><br />
<script language="javascript"><br />
document.form.name.style.color = "red";<br />
</script><br />
<?php<br />
}<br />
<br />
if ( (empty( $EMail )) || ( ($EMail == $emailOrigValue) ) )<br />
{<br />
$errmsg .= "enter your email ... <br />"; $valid = false;<br />
}<br />
<br />
<br />
if($valid!=true) // there are errors so display error message<br />
{<br />
echo($errmsg);<br />
}<br />
<br />
else<br />
{<br />
// send<br />
<br />
echo "<B>Attempting to send message</b></BR></BR>\n";<br />
<br />
$userip = ($_SERVER['X_FORWARDED_FOR']) ? $_SERVER['X_FORWARDED_FOR'] : $_SERVER['REMOTE_ADDR'];<br />
<br />
if( get_magic_quotes_gpc() == 1 ) {<br />
$_POST["Subject"] = stripslashes( $_POST["Subject"] );<br />
$_POST["Body"] = stripslashes( $_POST["Body"] );<br />
}<br />
<br />
if( mail( '"' . $eMail[$_POST["To"]][0] . '" <' . $eMail[$_POST["To"]][1] . '>',<br />
$_POST["Subject"], $_POST["Body"],<br />
'Return-Path: "' . $_POST["From"] . '" <' . $_POST["EMail"] . ">\n"<br />
. 'From: "' . $_POST["From"] . '" <' . $_POST["EMail"] . ">\n"<br />
. 'Reply-To: "' . $_POST["From"] . '" <' . $_POST["EMail"] . ">\n"<br />
. "X-Mailer: PHP/" . phpversion() . "\n"<br />
. "X-From-IP: " . $userip ) )<br />
echo "Message Sent Successfully";<br />
<br />
else<br />
echo "UNABLE To Send Message.";<br />
}<br />
}<br />
?><br />
</body><br />
</html><!--content-->Try the "Perl" Forum<!--content-->The most common so called web browser generally doesn't understand HTTP so try also putting those cache clearing headers into meta http-equiv tags in the HTML of your pages.<!--content-->Originally posted by ray326 <br />
The most common so called web browser generally doesn't understand HTTP so try also putting those cache clearing headers into meta http-equiv tags in the HTML of your pages. <br />
<br />
i'm really not too well up on this -- do you mean aswell as what i've got or instead of what i've got<br />
<br />
also would you mind giving me a quick one line example<br />
<br />
ps writing mainly for IE and Moz<br />
<br />
<br />
thanks<!--content-->Ok this is just off the top of my head but this is what I think those headers would look like imbedded as meta tags in the head of your HTML page.<br />
<br />
<meta http-equiv="Expires" content="0"><br />
<meta http-equiv="Cache-Control" content="no-cache"><br />
<meta http-equiv="Pragma" content="no-cache"><!--content-->
 
Back
Top