Page 1 of 2
form submit >> redirect
Posted: Sat Feb 14, 2004 12:14 pm
by joejoe
Bit basic this I'm sure, looking round at the other posts. Trying to get a form on submission to go to a ready-made success page or if the fields haven't all been filled in to a different ready-made unsuccessful page.
Wonder if you could tell me what's going wrong with this? Or suggest how else I could do this. Thanks.
At the beginning of the page:
<?
ob_start();
?>
Later on:
<?
if ($submit) { // if the form was sent do the following
if($name && $subject && $email && $message ) { // if all field are filled-in send email
mail("
me@mysite.com","$subject","$message","From: $name <$email>") or die("email error");
header("Location:
http://yoursite.com/form_success.php");
exit();
} else {
header("Location:
http://yoursite.com/form_unsuccess.php");
exit();
}
}else{
//display the form
?>
<form action="" method="post" name="contact">
Name: <br>
<input type="text" name="name">
<br>
Email: <br>
<input type="text" name="email">
<br>
Subject: <br>
<input type="text" name="subject">
<br>
Text:<br>
<textarea name="message" cols="40" rows=""></textarea>
<br>
<input type="submit" name="submit" value="Send">
<input type="reset" name="Reset" value="Reset">
</form>
<?php
}//end else
?>
Posted: Sat Feb 14, 2004 12:15 pm
by Straterra
Header can only be used if nothing has been put to the browser. This includes all echos, prints, anything OUT of PHP, a blank first line...
Posted: Sat Feb 14, 2004 12:18 pm
by Illusionist
so what is wrong? what is the error? have oyu even tested it to see if it works?
you might want to change this:
<form action="" method="post" name="contact">
to:
<form action="<?php= PHP_SELF ?>" method="post">
Posted: Sat Feb 14, 2004 12:40 pm
by joejoe
Been trying different variations out for quite a while with different error messages actually.
For the present above, including the change to the form I get parsing errors. e.g.
Parse error: parse error in /home/mysite/public_html/faq.php on line 183 - which is in the form - <form action="<?php= PHP_SELF ?>" method="post">.
The error I get for the code with the <form action="" method="post" name="contact"> - is another parsing error which refers to the line after all the code on the page has finished.
Any more ideas would be very welcome.
Posted: Sat Feb 14, 2004 12:41 pm
by Straterra
Use this instead.
Code: Select all
<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">
Posted: Sat Feb 14, 2004 12:42 pm
by Illusionist
oops, forgot the ;
<form action="<?php= PHP_SELF; ?>" method="post">
Posted: Sat Feb 14, 2004 12:44 pm
by Straterra
Um..Why are you putting an equal sign in there?
Posted: Sat Feb 14, 2004 12:48 pm
by Illusionist
its the same thing....
http://us4.php.net/echo
Code: Select all
echo() also has a shortcut syntax, where you can immediately follow the opening tag with an equals sign. This short syntax only works with the short_open_tag configuration setting enabled.
and im used to doing it that way in ASP...
Posted: Sat Feb 14, 2004 12:49 pm
by Straterra
Ah ok...Just asking..

Posted: Sat Feb 14, 2004 1:01 pm
by joejoe
Sorry guys, am getting the line 232 parsing error - at the end of the page with the line <form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post"> inserted instead of the other.
Is the top bit OK?
<?
ob_start();
?>
Posted: Sat Feb 14, 2004 1:05 pm
by Illusionist
show the code around that form
Posted: Sat Feb 14, 2004 1:10 pm
by joejoe
<p class="text">If you think we should add any information to this FAQ,
please do let us know as we would like it to be as helpful as possible.
Thanks.
<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">
Name: <br>
<input type="text" name="name">
<br>
Email: <br>
<input type="text" name="email">
<br>
Subject: <br>
<input type="text" name="subject">
<br>
Text:
<textarea name="message" cols="40" rows=""></textarea>
<br>
<br>
<input type="submit" name="submit" value="Send">
<input type="reset" name="Reset" value="Reset">
</form>
<?
ob_start();
if ($submit) { // if the form was sent do the following
if($name && $subject && $email && $message ) { // if all field are filled-in send email
mail("
me@mysite.com","$subject","$message","From: $name <$email>") or die("email error");
echo "Message Sent"; // if all went well, display message was sent
header("Location:
http://www.mysite.com/form_success.php");
exit();
} else {
header("Location:
http://www.mysite.com/form_unsuccess.php");
exit();
}
}else{
//display the form
?>
</td>
<td width="20" bgcolor="#FFFFFF" height="1523"> </td>
</tr>
<tr>
<td width="600" bgcolor="#FFFFFF" colspan="2"> </td>
</tr>
<tr valign="top">
<td colspan="4" bgcolor="#FF7700">
<div align="right"><!-- #BeginLibraryItem "/Library/copyright.lbi" --><font face="Arial, Helvetica, sans-serif" size="-1"><b>Site XX.com ©
2004</b></font><!-- #EndLibraryItem --></div>
</td>
</tr>
</table>
</body>
</html>
Posted: Sat Feb 14, 2004 1:15 pm
by Illusionist
... what? your code is really confusing... YOu have teh form at the very top... and then down near the bottom in your if and else's you have a commented area taht says display form, but htere is no form there... what int he world is giving you the error? what line?
Posted: Sat Feb 14, 2004 1:23 pm
by joejoe
Sorry about this. Code was suggested to me - should have seen what I started with!!
Parse error: parse error in /home/mysite/public_html/faq.php on line 233
line 233 is the line after all of the code on the page.
Posted: Sat Feb 14, 2004 1:28 pm
by Illusionist
is what you posted above the whole page? surely not, but is that the bottom of the page? if so then you need to add
to the very bottom... other than that, i dont know