views:

34

answers:

3

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 = "";
while(list($key, $val) = each($HTTP_POST_VARS)) {
$body .= "$key: $val \n";
}

mail("[email protected]", 
"Rental Request",
$body);


?>

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.

+1  A: 

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');
exit();

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.
Pascal MARTIN
Damn you, Pascal! - 22 seconds quicker than me! :)
Raise
@Raise : huhu ;-) *(probably doesn't matter that much ^^ )*
Pascal MARTIN
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
+2  A: 

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.

Raise
A: 

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

ocdcoder