directing to a "thanks" page with PHP (Full Version)

All Forums >> [Web Development] >> ASP and Database



Message


craigj1303 -> directing to a "thanks" page with PHP (5/1/2008 11:20:05)

Hi

I know nothing about PHP and I am trying to come up with a basic contact form for my website. The form is no problem and I have cut and pasted some PHP which I have tried and tested OK for sending me mail.

The only thing I want to change is what happens after the form is submitted. I want to direct the client to a "thanks for your comments" page where they can then carry on navigating their way around the site. At the moment they just get a message saying "data has been submitted" and would have to use the back button to get back.

Can anyone advise me how to direct them to a different page? Below is the .php file I am using:

<?php
if(isset($_POST['submit'])) {
$to = "xxxxxxxxxx@hotmail.com";
$subject = "Matchday Programmes";
$name_field = $_POST['name'];
$email_field = $_POST['email'];
$message = $_POST['message'];

$body = "From: $name_field\n E-Mail: $email_field\n Message:\n $message";

echo "Data has been submitted to $to!";
mail($to, $subject, $body);
} else {
echo "blarg!";
}
?>

Thanks in advance

Craig




rdouglass -> RE: directing to a "thanks" page with PHP (5/1/2008 12:21:33)

I use something like this:

echo "<script>window.location=\"/mypage.htm"</script>";

With this tho, JS needs to be enabled.

Hope it helps.




craigj1303 -> RE: directing to a "thanks" page with PHP (5/1/2008 12:41:42)

Hi

When I add that piece of code in place of the existing echo I get this message:

Parse error: syntax error, unexpected $end in /home/fhlinux163/a/anyoldirons.me.uk/user/htdocs/mailer.php on line 17

Can you tell me where I need to add your piece of code and what (if anything) I need to remove from my code to make this work?




rdouglass -> RE: directing to a "thanks" page with PHP (5/1/2008 12:56:01)

quote:

echo "<script>window.location=\"/mypage.htm"</script>";


Ooops. Sorry, I missed a backslash:

echo "<script>window.location=\"/mypage.htm\"</script>";

That any better?




craigj1303 -> RE: directing to a "thanks" page with PHP (5/1/2008 13:09:29)

brilliant, thanks!




ou812 -> RE: directing to a "thanks" page with PHP (5/1/2008 13:44:21)

If you wanted to use PHP to do this you could use the header command. Something like
header("location:mypage.php");

You can view a bit more here:
http://www.w3schools.com/php/func_http_header.asp
or here:
http://www.php.net/header




Page: [1]

Valid CSS!




Forum Software © ASPPlayground.NET Advanced Edition 2.4.5 ANSI
0.046875