This PHP file blinks on the html form but quickly changes to the text of the error file, error.htm. I have looked it over forever. Please help.
// redirect to success page
if ($success){
print "<meta http-equiv=\“refresh\” content=\"0;URL=http://www.globalfreeenterprise.com/error.htm\\“>” ;
}
else{
print “<meta http-equiv=\“refresh\” content=\“0;URL=ok.htm\”>”;
}
I have been suspecting the redirect code above (which is at the end of the file), but I can’t find anything wrong with it. Here is the file:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
<title>contact.htm</title>
<meta name="description" content="Free Enterprise." />
<meta name="keywords" content="Free Enterprise" />
<meta http-equiv="Content-Type" content="text/html;charset=iso-8859-1" />
<link rel="stylesheet" type="text/css" href="gfe.css" />
</head>
<body class="body0">
<div style="position: absolute; top: 20px; left: 20px;">
<div style="width: 900px; background-color: transparent; color: #000000;
font-family: times new roman, geneva, sans-serif, arial, helvetica, verdana, roman;
font-size:18px;
line-height: 30px;
border-bottom-width: 2px;
border-left-width: 2px;
border-right-width: 2px;
border-top-width: 2px;> <!-- div0 -->
<div style="margin-left: 40px; margin-right: 40px;"></div>
<div class="aa1"><center>Title</center></div>
<div class="aa1"><center> Label </center></div>
Please send comments to <a href="mailto:****@********************.***">****@********************.***</a>
<br /><br />
<!-- Website Contact Form -->
<br /><br />
<br /><br />
<!-- <form method="POST" action="contact.php"> -->
<form method="POST" action="<?php echo $PHP_SELF;?>">
<br /><br />
<br /><br />
Fields marked (*) are required.
<br />
<br />
<!--
Username:
<input type="text" name="Username" ><br />
Password:
<input type="password" name="password" ><br />
<input type="submit" value="Submit Info!"><br />
-->
<br />
<br />
Contact Person:
<br />
First Name: *
<br />
<br />
<input type="text" name="First" value="My names is " size="18" maxlength="30">
<br />
<br />
Last Name: * <br />
<input type="text" name="Last">
<br />
<br />
Age: <br />
<select name="Age">
<option>Not Selected</option>
<option>Less than 18</option>
<option>18 - 64</option>
<option>65 or older</option>
</select>
<br />
<br />
Street Address: *<br />
<input type="text" name="Address">
<br />
<br />
Village, Town, or City: * <br />
<input type="text" name="City">
<br />
<br />
<br />
<br />
<p>Zip Code or Postal Code: *<br />
<input type="text" name="Zip">
<br />
<br />
Telephone Number: * <br />
<input type="text" name="Telephone">
<br />
<br />
Email Address: * <br />
<input type="text" name="Email">
<br />
<br />
Website Address: * <br />
<input type="text" name="Website">
<br />
<br />
Questions and Comments:
<br />
<br />
<textarea name="Questions" rows="30" cols="90">
</textarea>
<input type="submit" name="submit" value="Submit">
<br />
<br />
<input type="reset" value="Clear Form">
</form>
</div> <!-- div0 -->
<?
// get posted data into local variables
$EmailFrom = "Contact Form at http://www.globalfreeenterprise.com";
$EmailTo = "****@********************.***";
$Subject = "Customer Contact";
$First = Trim(stripslashes($_POST['First']));
$Last = Trim(stripslashes($_POST['Last']));
$Age = $_POST['Age'];
$Address = Trim(stripslashes($_POST['Address']));
$City = Trim(stripslashes($_POST['City']));
$State = $_POST['State'];
$Zip = Trim(stripslashes($_POST['Zip']));
$Country = Trim(stripslashes($_POST['Country']));
$Telephone = Trim(stripslashes($_POST['Telephone']));
$Email = Trim(stripslashes($_POST['Email']));
$Website = Trim(stripslashes($_POST['Website']));
$Comments = Trim(stripslashes($_POST['Questions']));
// validation
$validationOK=true;
if (Trim($First)=="") $validationOK=false;
if (Trim($Last)=="") $validationOK=false;
if (Trim($Address)=="") $validationOK=false;
if (Trim($City)=="") $validationOK=false;
if (Trim($State)=="") $validationOK=false;
if (Trim($Zip)=="") $validationOK=false;
if (Trim($Country)=="") $validationOK=false;
if (Trim($Telephone)=="") $validationOK=false;
if (Trim($Email)=="") $validationOK=false;
if (Trim($Website)=="") $validationOK=false;
if (!$validationOK) {
print "<meta http-equiv=\\"refresh\\" content=\\"0;URL=http://www.globalfreeenterprise.com/error.htm\\">";
exit;
}
// prepare email body text
$Body .= "First: ";
$Body .= $First;
$Body .= "\
";
$Body .= "Last: ";
$Body .= $Last;
$Body .= "\
";
$Body .= "Age: ";
$Body .= $Age;
$Body .= "\
";
$Body .= "Address: ";
$Body .= $Address;
$Body .= "\
";
$Body .= "City: ";
$Body .= $City;
$Body .= "\
";
$Body .= "State: ";
$Body .= $State;
$Body .= "\
";
$Body .= "Zip: ";
$Body .= $Zip;
$Body .= "\
";
$Body .= "Country: ";
$Body .= $Country;
$Body .= "\
";
$Body .= "Telephone: ";
$Body .= $Telephone;
$Body .= "\
";
$Body .= "Email: ";
$Body .= $Email;
$Body .= "\
";
$Body .= "Website: ";
$Body .= $Website;
$Body .= "\
";
$Body .= "Comments: ";
$Body .= $Comments;
$Body .= "\
";
// send email
$success = mail($EmailTo, $Subject, $Body, "From: <$EmailFrom>");
// redirect to success page
if ($success){
print "<meta http-equiv=\\"refresh\\" content=\\"0;URL=http://www.globalfreeenterprise.com/error.htm\\">";
}
else{
print "<meta http-equiv=\\"refresh\\" content=\\"0;URL=ok.htm\\">";
}
?>
</body>
</html>
Jim Adrian
<snip/>
ScallioXTX and guido2004,
The file works and I now know something about why. Thank you for all of your help.
Jim Adrian
<snip/>
Hi Jim. Please put code between the appropriate code tags, it makes it so much easier to read
Let me ask you a question: when do you think the php code is executed? After the user posts the form?
Wrong! It is executed (server side) before the resulting html page is sent to your browser. So the browser will show the form, and then after 0 seconds (ie immediately) it will redirect to the error page (because no form fields were filled, so the validation failed).
guido2004 said
Hi Jim. Please put code between the appropriate code tags, it makes it so much easier to read
Let me ask you a question: when do you think the php code is executed? After the user posts the form?
Wrong! It is executed (server side) before the resulting html page is sent to your browser. So the browser will show the form, and then after 0 seconds (ie immediately) it will redirect to the error page (because no form fields were filled, so the validation failed).
guido2004,
Thank you for this answer. I have some appreciation for the timing problem, but I don’t have a clue as to how to fix it. Where should I go from here?.
Thank you for your help.
Jim Adrian
<snip/>
if (isset($_POST['Submit'])) // value of your submit button
{
// validation etc
}
And to quote people, press the “quote” button in their post.
To post PHP code, like I did above:
[noparse]
if (isset($_POST['Submit'])) // value of your submit button
{
// validation etc
}
[/noparse]
rpkamp:
if (isset($_POST['Submit'])) // value of your submit button
{
// validation etc
}
And to quote people, press the “quote” button in their post.
To post PHP code, like I did above:
[noparse]
if (isset($_POST['Submit'])) // value of your submit button
{
// validation etc
}
[/noparse]
Exactly. And put the whole validation part (included in the if that checks if the form has been submitted) at the top of your script. That way it’ll be the first thing that is executed when the form is submitted.
Btw, you might want to do the redirect using header
Thank you very much . I tried it placing the second curly bracket in various places in my original file. Is there something about this file of mine that needs to be modified further to get both the form to appear (as it now can) and to get the redirect choice to work? Please let me know where to put the second curly bracket and whether that is all that is wrong.
Thank you for your help.
Jim Adrian
<snip/>
<?php
if ($_POST['Submit'])
{
// get posted data into local variables
$EmailFrom = "Contact Form at http://www.globalfreeenterprise.com";
$EmailTo = "****@********************.***";
$Subject = "Customer Contact";
$First = Trim(stripslashes($_POST['First']));
$Last = Trim(stripslashes($_POST['Last']));
$Age = $_POST['Age'];
$Address = Trim(stripslashes($_POST['Address']));
$City = Trim(stripslashes($_POST['City']));
$State = $_POST['State'];
$Zip = Trim(stripslashes($_POST['Zip']));
$Country = Trim(stripslashes($_POST['Country']));
$Telephone = Trim(stripslashes($_POST['Telephone']));
$Email = Trim(stripslashes($_POST['Email']));
$Website = Trim(stripslashes($_POST['Website']));
$Comments = Trim(stripslashes($_POST['Questions']));
// validation
$validationOK=true;
if (Trim($First)=="") $validationOK=false;
if (Trim($Last)=="") $validationOK=false;
if (Trim($Address)=="") $validationOK=false;
if (Trim($City)=="") $validationOK=false;
if (Trim($State)=="") $validationOK=false;
if (Trim($Zip)=="") $validationOK=false;
if (Trim($Country)=="") $validationOK=false;
if (Trim($Telephone)=="") $validationOK=false;
if (Trim($Email)=="") $validationOK=false;
if (Trim($Website)=="") $validationOK=false;
if (!$validationOK) {
header('Location: http://www.globalfreeenterprise.com/error.htm');
exit;
}
// prepare email body text
$Body .= "First: ";
$Body .= $First;
$Body .= "\
";
$Body .= "Last: ";
$Body .= $Last;
$Body .= "\
";
$Body .= "Age: ";
$Body .= $Age;
$Body .= "\
";
$Body .= "Address: ";
$Body .= $Address;
$Body .= "\
";
$Body .= "City: ";
$Body .= $City;
$Body .= "\
";
$Body .= "State: ";
$Body .= $State;
$Body .= "\
";
$Body .= "Zip: ";
$Body .= $Zip;
$Body .= "\
";
$Body .= "Country: ";
$Body .= $Country;
$Body .= "\
";
$Body .= "Telephone: ";
$Body .= $Telephone;
$Body .= "\
";
$Body .= "Email: ";
$Body .= $Email;
$Body .= "\
";
$Body .= "Website: ";
$Body .= $Website;
$Body .= "\
";
$Body .= "Comments: ";
$Body .= $Comments;
$Body .= "\
";
// send email
$success = mail($EmailTo, $Subject, $Body, "From: <$EmailFrom>");
if ($success) {
// redirect to success page
header('Location: http://www.globalfreeenterprise.com/error.htm');
} else{
header('Location: ok.htm');
}
} // the if ($_POST['Submit']) ends here
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
<title>contact.htm</title>
<meta name="description" content="Free Enterprise." />
<meta name="keywords" content="Free Enterprise" />
<meta http-equiv="Content-Type" content="text/html;charset=iso-8859-1" />
<link rel="stylesheet" type="text/css" href="gfe.css" />
</head>
<body class="body0">
<div style="position: absolute; top: 20px; left: 20px;">
<div style="width: 900px; background-color: transparent; color: #000000;
font-family: times new roman, geneva, sans-serif, arial, helvetica, verdana, roman;
font-size:18px;
line-height: 30px;
border-bottom-width: 2px;
border-left-width: 2px;
border-right-width: 2px;
border-top-width: 2px;> <!-- div0 -->
<div style="margin-left: 40px; margin-right: 40px;"></div>
<div class="aa1"><center>Title</center></div>
<div class="aa1"><center> Label </center></div>
Please send comments to <a href="mailto:****@********************.***">****@********************.***</a>
<br /><br />
<!-- Website Contact Form -->
<br /><br />
<br /><br />
<!-- <form method="POST" action="contact.php"> -->
<form method="POST" action="<?php echo $PHP_SELF;?>">
<br /><br />
<br /><br />
Fields marked (*) are required.
<br />
<br />
<!--
Username:
<input type="text" name="Username" ><br />
Password:
<input type="password" name="password" ><br />
<input type="submit" value="Submit Info!"><br />
-->
<br />
<br />
Contact Person:
<br />
First Name: *
<br />
<br />
<input type="text" name="First" value="My names is " size="18" maxlength="30">
<br />
<br />
Last Name: * <br />
<input type="text" name="Last">
<br />
<br />
Age: <br />
<select name="Age">
<option>Not Selected</option>
<option>Less than 18</option>
<option>18 - 64</option>
<option>65 or older</option>
</select>
<br />
<br />
Street Address: *<br />
<input type="text" name="Address">
<br />
<br />
Village, Town, or City: * <br />
<input type="text" name="City">
<br />
<br />
<br />
<br />
<p>Zip Code or Postal Code: *<br />
<input type="text" name="Zip">
<br />
<br />
Telephone Number: * <br />
<input type="text" name="Telephone">
<br />
<br />
Email Address: * <br />
<input type="text" name="Email">
<br />
<br />
Website Address: * <br />
<input type="text" name="Website">
<br />
<br />
Questions and Comments:
<br />
<br />
<textarea name="Questions" rows="30" cols="90">
</textarea>
<input type="submit" name="submit" value="Submit">
<br />
<br />
<input type="reset" value="Clear Form">
</form>
</div> <!-- div0 -->
</body>
</html>