PHP redirection to static page...Help please.

Associate
Joined
21 Jun 2005
Posts
1,788
Location
EVO Triangle, N.Wales
Somebody did a form for a site I am doing a few small adjustments to. I have zero experience with PHP, but the site has a form for a request for a quotation. Once the form is filled out and the user clicks "submit" a message saying "Thank you, a representive will contact you shortly" appears on the same page.

What I need is for it all to stay the same, but instead of the thank you message, once the user hits "submit", I need to have the user jumped to a static html page that says Thank you etc, instead of staying on the quotation request page. The code is below, any help would be massively appreciated.

Code:
<?

if($require_gas == "Gas"){ $gas_checked = "CHECKED"; }
if($require_elec == "Electricity"){ $elec_checked = "CHECKED"; }
if($require_both == "Both"){ $both_checked = "CHECKED"; }

$form = "<br> 
		( <font color='#FF0000'>Mandatory fields *</font> )<br>

				<form name=\"Quote\" method=\"post\" action=\"$PHP_SELF#theform\">
                  <INPUT TYPE=\"hidden\" NAME=\"op\" VALUE=\"ds\">
                  <table width=\"300\" border=\"1\" cellpadding=\"5\" cellspacing=\"0\" bordercolor=\"#FF6600\" bgcolor=\"#CBCBCB\">
                    
                    <tr align=\"left\" valign=\"middle\"> 
                      <td height=\"40\"><strong>Name</strong></td>
                      <td><input type=\"text\" name=\"txtName\" value=\"$txtName\" size=\"22\"> <font color='#FF0000'>*</font></td>
                    </tr><tr align=\"left\" valign=\"middle\"> 
                      <td width=\"97\" height=\"50\"><strong>Company</strong></td>
                      <td width=\"166\"><input type=\"text\" name=\"txtCompany\" value=\"$txtCompany\" size=\"25\"></td>
                    </tr>
                    <tr align=\"left\" valign=\"top\"> 
                      <td><strong>Address</strong></td>
                      <td><textarea cols=\"20\" rows=\"3\" name=\"txtAddress\">$txtAddress</textarea></td>
                    </tr>
                    <tr align=\"left\" valign=\"middle\"> 
                      <td height=\"40\"><strong>Postcode</strong></td>
                      <td><input type=\"text\" name=\"txtPostcode\" value=\"$txtPostcode\" size=\"22\"></td>
                    </tr>
                    <tr align=\"left\" valign=\"middle\"> 
                      <td height=\"40\"><strong>Telephone</strong></td>
                      <td><input type=\"text\" name=\"txtTelephone\" value=\"$txtTelephone\" size=\"22\"> <font color='#FF0000'>*</font></td>
                    </tr>
                    <tr align=\"left\" valign=\"middle\"> 
                      <td height=\"40\"><strong>Email</strong></td>
                      <td><input type=\"text\" name=\"txtEmail\" value=\"$txtEmail\" size=\"22\"></td>
                    </tr>
                    <tr align=\"left\" valign=\"middle\"> 
                      <td height=\"40\"><strong>Current contract end date</strong></td>
                      <td><input type=\"text\" name=\"txtContract\" value=\"$txtContract\" size=\"15\"></td>
                    </tr>
                    <tr align=\"left\" valign=\"middle\"> 
                      <td height=\"50\"><strong>Monthly spend exl. VAT</strong></td>
                      <td><input type=\"text\" name=\"txtMonthly\" value=\"$txtMonthly\" size=\"15\"></td>
                    </tr>
                    <tr align=\"left\" valign=\"middle\"> 
                      <td height=\"50\"><strong>Please tick the type of quote required</strong></td>
                      <td>Gas 
                        <input type=\"checkbox\" name=\"require_gas\" value=\"Gas\" $gas_checked> 
                        &nbsp;&nbsp;Electricity 
                        <input type=\"checkbox\" name=\"require_elec\" value=\"Electricity\" $elec_checked> 
                        &nbsp;Both 
                        <input type=\"checkbox\" name=\"require_both\" value=\"Both\" $both_checked>  <font color='#FF0000'>*</font></td>
                    </tr>
                    <tr align=\"left\" valign=\"middle\"> 
                      <td colspan=\"2\" align=\"right\"> <input type=\"submit\" name=\"Submit\" value=\"Send Me A Quote &raquo; &raquo;\"> 
                      </td>
                    </tr>
                  </table>
                </form>";


if($op == "ds"){



	if(($txtName == "")||($txtTelephone == "")){
	echo "<p>
			<center><font color='#FF0000'><b>Please enter both your name and telephone number</b><font></center>
			</p>
			$form";
	}
	elseif(($require_gas == "")&&($require_elec == "")&&($require_both == "")){
	if($require_gas == "GAS"){ $gas_checked = "CHECKED"; }
	if($require_elec == "ELECTRICITY"){ $elec_checked = "CHECKED"; }
	if($require_both == "BOTH"){ $both_checked = "CHECKED"; }
	echo "<p>
			<center><font color='#FF0000'><b>Please select at least one type of quote required</b><font></center>
			</p>
			$form";
	}else{
			## okay to send the email and add details to the database


			$connection = @mysql_connect("localhost", "onlineenergy", "yvvm72") or die("Couldn't connect.");
			
			$db = @mysql_select_db("onlineenergy", $connection) or die("Couldn't select database.");

				if($require_gas == "Gas"){ $require_quotes = "Gas Quote Required<br>"; }
				if($require_elec == "Electricity"){ $require_quotes .= "Electricity Quote Required<br>"; }
				if($require_both == "Both"){ $require_quotes .= "Both Quotes Required<br>"; }


			$sql = mysql_query("INSERT INTO `quotes` VALUES 
			('', '$txtName', '$txtCompany', '$txtAddress', '$txtPostcode', '$txtTelephone', '$txtEmail', '$txtContract', '$txtMonthly', '$require_quotes')")
			or die("Cannot query database " . mysql_error());

			
			$to = "new@*********8.co.uk";
			#$to = "***************@hotmail.com, stephen@**********.net";
			
			$subject = "GAS/ELECTRICITY ENQUIRY";

			#$txtAddress = nl2br($txtAddress);
			
			$msg = "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\">

<html>
<head>
<title> - Contact</title>
<style>
td{font-family:Tahoma;font-size:11px;}
a{color:#F67520}
a:hover{color:#6F6F6F}
.cap{font-weight:bold;text-decoration:underline;}
.menu{color:#000000;text-decoration:none;}
</style>
<meta http-equiv=\"Content-Type\" content=\"text/html; charset=iso-8859-1\">
</head>

<body link=\"#FF6600\" leftmargin=\"10\" topmargin=\"10\" rightmargin=\"10\" bottommargin=\"10\">

	 <table width=\"350\" border=\"1\" cellpadding=\"5\" cellspacing=\"0\" bgcolor=\"#FFFFFF\">
                    <tr align=\"left\" valign=\"middle\" bgcolor=\"#F3F3F3\"> 
                      <td height=\"40\"><strong>Name</strong></td>
                      <td>$txtName</td>
                    </tr>
		    <tr align=\"left\" valign=\"middle\"> 
                      <td width=\"97\" height=\"50\"><strong>Company</strong></td>
                      <td width=\"166\">$txtCompany</td>
                    </tr>
                    <tr align=\"left\" valign=\"top\" bgcolor=\"#F3F3F3\"> 
                      <td><strong>Address</strong></td>
                      <td>".nl2br($txtAddress)."</td>
                    </tr>
                    <tr align=\"left\" valign=\"middle\"> 
                      <td height=\"40\"><strong>Postcode</strong></td>
                      <td>$txtPostcode</td>
                    </tr>
                    <tr align=\"left\" valign=\"middle\" bgcolor=\"#F3F3F3\"> 
                      <td height=\"40\"><strong>Telephone</strong></td>
                      <td>$txtTelephone</td>
                    </tr>

                    <tr align=\"left\" valign=\"middle\"> 
                      <td height=\"40\"><strong>Email</strong></td>
                      <td>$txtEmail</td>
                    </tr>
                    <tr align=\"left\" valign=\"middle\" bgcolor=\"#F3F3F3\"> 
                      <td height=\"40\"><strong>Current contract end date</strong></td>
                      <td>$txtContract</td>
                    </tr>
                    <tr align=\"left\" valign=\"middle\"> 
                      <td height=\"50\"><strong>Monthly spend exl. VAT</strong></td>
                      <td>$txtMonthly</td>
                    </tr>
                    <tr align=\"left\" valign=\"middle\" bgcolor=\"#F3F3F3\"> 
                      <td height=\"50\">Type of quote required</td>
                      <td>";
					if($require_gas == "Gas"){ $msg .= "Gas Quote Required<br>"; }
					if($require_elec == "Electricity"){ $msg .= "Electricity Quote Required<br>"; }
					if($require_both == "Both"){ $msg .= "Both Quotes Required<br>"; }
			
					$msg .= "</td>
                    </tr>
                  </table>";
			
			$headers = "MIME-Version: 1.0\nContent-Type: text/html;charset=iso-8859-1\nX-Priority:3\nX-MSMail-Priority: Normal\nFrom: Whatever.comQuote Form<[email protected]>\n";
			
			mail("$to", $subject, $msg, $headers);

		echo "<p>
			<center><font color='#006600'><b>Thank you. A representative will contact you shortly</b><font></center>
			</p>
			";

	}

} else {

## show the form

echo "$form";

}

?>

Cheers.
 
Should have the user taken to a page saying thank you blah blah, but that has a redirect on it back to your main site, so they stay on it :)


PHP:
$url = "index.php"; // target of the redirect
$delay = "3"; // 3 second delay

echo '<meta http-equiv="refresh" content="'.$delay.';url='.$url.'">';
 
Back
Top Bottom