Take the 2-minute tour ×

I'm very new to back-end web work and I'm trying to create a form for my theatre wherein someone can submit a space inquiry form. I have the form made, it works, but what I want it to do is after they hit 'submit' and the form is validated and emailed to us, they'll be redirected to a "thank you" page. I've tried using the behaviors in Dreamweaver CS3 but if I use onClick->goto URL, it will go, but if the page doesn't validate, I'll still get the incomplete warning and they have no chance to fix it. Right now, the validation works, but I don't have the onClick->goto URL in place and it just refreshes with a blank form.

Here's the PHP I've been using:


if(sizeof($_POST)) {
$body = "";
$body .= "$key: $val \n";

"Rental Request",


here's the Javascript:

   <form action=<? echo $PHP_SELF; ?> method="post" name="rentalRequest"  onSubmit="MM_validateForm('firstName','','R','lastName','','R','organization','','R','emailAddress','','RisEmail','phone','','R','address1','','R','city','''R','guestNumber','','RisNum','timeStart','','R');return document.MM_returnValue">    

I've spent the better part of the day researching this online and cannot find an answer. Any help would be greatly appreciated. I'm willing to send cookies to whomever can help me out.

share|improve this question
add comment

3 Answers

You have to send an HTTP Location header ; this can be done, in PHP, with code such as this example :

header('Location: http://www.example.com');

A couple of notes :

  • The header function must be called before any output is sent to the browser.
  • The exit() call makes sure that your script really ends immediatly after the call to header()
  • In theory, you should use an absolute URL (such as http://www.example.com/test.php), for the HTTP Location header -- even if a relative URL (such as test.php) generally works in browsers.
share|improve this answer
Damn you, Pascal! - 22 seconds quicker than me! :) –  Raise Mar 10 '10 at 22:01
@Raise : huhu ;-) (probably doesn't matter that much ^^ ) –  Pascal MARTIN Mar 10 '10 at 22:02
Ok, that makes sense but where does it go? I've tried putting it in the php script above and it's giving me errors. Does it need to go with the submit button? Remember, I'm a noob. Walk me through this and cookies will be yours, seriously. –  WoollyMammoth Mar 11 '10 at 16:22
add comment

In PHP, you can redirect using this code:

header("Location: thanks.php");

Add this after you have handled the form submission. For completeness, consider adding exit(); after the header() function to prevent any further execution.

share|improve this answer
add comment

You can use the header() function in php to change the 'location' variable, read more @ http://php.net/manual/en/function.header.php :-)

share|improve this answer
add comment

Your Answer


