Page 1 of 1

HELP Making form go to seperate PHP file

Posted: Wed Apr 14, 2004 9:54 am
by CraigB
What I have is a PHP contact form on my Contact page called by:
<form METHOD=POST ACTION="contact_form.php">
Now here is the contact_form.php:
<?
// THIS IS THE BEGIINNING OF THE PHP CODE

$name = @$HTTP_POST_VARS['name'];
$address = @$HTTP_POST_VARS['address'];
$state = @$HTTP_POST_VARS['state'];
$city = @$HTTP_POST_VARS['city'];
$zip = @$HTTP_POST_VARS['zip'];
$country = @$HTTP_POST_VARS['country'];
$phone = @$HTTP_POST_VARS['phone'];
$email = @$HTTP_POST_VARS['email'];
$comments = @$HTTP_POST_VARS['comments'];
$fax = @$HTTP_POST_VARS['fax'];
$error_msg="";
$msg="";

if(!$name){
$error_msg .= "Your name \n";
}
if($name){
$msg .= "Name: \t $name \n";
}

if(!$address){
$error_msg .= "Your address \n";
}
if($address){
$msg .= "Address: \t $address \n";
}

if(!$city){
$error_msg .= "Your City \n";
}
if($city){
$msg .= "City: \t $city \n";
}

if(!$state){
$error_msg .= "Your State \n";
}
if($state){
$msg .= "State: \t $state \n";
}

if(!$country){
$error_msg .= "Your country \n";
}
if($country){
$msg .= "Country: \t $country \n";
}

if(!$zip){
$error_msg .= "Your zip \n";
}
if($zip){
$msg .= "Zip: \t $zip \n";
}

if(!$phone){
$error_msg .= "Your phone \n";
}
if($phone){
$msg .= "Phone: \t $phone \n";
}

if(!$email){
$error_msg .= "Your email \n";
}
if($email){
if(!eregi("^[a-z0-9_]+@[a-z0-9\-]+\.[a-z0-9\-\.]+$", $email)){
echo 'That is not a valid email address. Please<a href="javascript:history.back()"> return </a> to the previous page and try again.';
exit;
}
$msg .= "Email: \t $email \n";
}

if($fax){
$msg .= "Fax: \t $fax \n";
}

if($comments){
$msg .= "Comments: \t $comments \n";
}
$sender_email="";

if(!isset($name)){
if($name==""){
$sender_name="Web Customer";
}
}else{
$sender_name=$name;
}
if(!isset($email)){
if($email==""){
$sender_email="Customer@website.com";
}
}else{
$sender_email=$email;
}
if($error_msg != ""){
echo"You didn't fill in these required fields:<br>"
. nl2br($error_msg) .'<br>Please <a href="javascript:history.back()"> return </a> to the'
." previous page and try again.";
exit;}
$mailheaders = "MIME-Version: 1.0\r\n";
$mailheaders .= "Content-type: text/plain; charset=iso-8859-1\r\n";
$mailheaders .= "From: $sender_name <$sender_email>\r\n";
$mailheaders .= "Reply-To: $sender_email <$sender_email>\r\n";
mail("support@hotmail.com","Contact form at Hotmail.com",stripslashes($msg), $mailheaders);
echo "<html> <head> <title>Thanks For Your Submission
</title>
</head>
<body>
<h2>Thank you for your feedback $name</h2>
";echo '<b>This is the information you submitted</b> <br>';echo nl2br(stripslashes($msg));echo '<br><br></body></html>';
//THIS IS THE END OF THE PHP CODE ?>
My question is, is there a way at the end of this code:
<html> <head> <title>Thanks For Your Submission
</title>
</head>
<body>
<h2>Thank you for your feedback $name</h2>
";echo '<b>This is the information you submitted</b> <br>';echo nl2br(stripslashes($msg));echo '<br><br></body></html>';
that I can make this part go to another PHP page
What happens is after you hit the submit button on the form, the "Thank you for your feedback" page goes to a blank page with the info the user submitted. What I want is for the info to go to my page so it looks like part of my site and not just a white page


This is what I placed on my own page
<h2>Thank you for your feedback $name</h2>
";echo '<b>This is the information you submitted</b> <br>';echo nl2br(stripslashes($msg));echo '<br><br>
Does this make sense? I would appreciate any help

Craig

Posted: Wed Apr 14, 2004 10:06 am
by TheBentinel.com
You could include() another PHP page after the message, would that give you what you want?

Or you could redirect to that other page before printing anything (use header()) and send the $msg along in the query string so you can redisplay the message.

From a user's standpoint, does it do them any good to display their message back to them? If you think not, then you could skip the message part.

Posted: Wed Apr 14, 2004 10:39 am
by CraigB
I agree on showing them their own message. I got this PHP form from Hotscripts and since I know little about PHP..but trying to learn slowly...I know I need to remove this part
<html> <head> <title>Thanks For Your Submission
</title>
</head>
<body>
<h2>Thank you for your feedback $name</h2>
";echo '<b>This is the information you submitted</b> <br>';echo nl2br(stripslashes($msg));echo '<br><br></body></html>';
how can I get the program to forward on to a thank you page? Can you show me what I need to put at the end of the file to make it forward.

Thanks for the help

Posted: Wed Apr 14, 2004 11:06 am
by CraigB
Okay, what I did is add
$new_location="http://location.com/folder1/contact/contact_form1.php";
sleep(1); // 1 second pause
header("Location: $new_location");
to the end of the file and took out
<html> <head> <title>Thanks For Your Submission
</title>
</head>
<body>
<h2>Thank you for your feedback $name</h2>
";echo '<b>This is the information you submitted</b> <br>';echo nl2br(stripslashes($msg));echo '<br><br></body></html>';
and it forwards just fine :D

What I need to know is how do I send the $name info along with the redirect so when it says thank you on the next page I can input their $name after Thank you?

Posted: Wed Apr 14, 2004 11:10 am
by phait
hi,
after the line:

Code: Select all

mail("support@hotmail.com","Contact form at Hotmail.com",stripslashes($msg), $mailheaders);
put the following:

Code: Select all

header("Location: path/to/yourPageThatYouWishToMoveTo.php");
and that will redirect the user to your new page.

Posted: Wed Apr 14, 2004 11:15 am
by phait
$new_location="http://location.com/folder1/contact/contact_form1.php";
$new_location .= '?name='.urlencode($name);
sleep(1); // 1 second pause
header("Location: $new_location");

then on the new page extract the var like so:
$name =$_GET['name'];
$name = urldecode($name);

echo($name);

I think that should do it.

Posted: Wed Apr 14, 2004 11:28 am
by CraigB
Thank you Phait, That's it!!!!! :lol: