form submit >> redirect
Moderator: General Moderators
form submit >> redirect
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
?>
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
?>
-
Illusionist
- Forum Regular
- Posts: 903
- Joined: Mon Jan 12, 2004 9:32 pm
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.
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.
-
Straterra
- Forum Regular
- Posts: 527
- Joined: Mon Nov 24, 2003 8:46 am
- Location: Indianapolis, Indiana
- Contact:
Use this instead.
Code: Select all
<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">-
Illusionist
- Forum Regular
- Posts: 903
- Joined: Mon Jan 12, 2004 9:32 pm
-
Illusionist
- Forum Regular
- Posts: 903
- Joined: Mon Jan 12, 2004 9:32 pm
its the same thing....
http://us4.php.net/echo
and im used to doing it that way in ASP...
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.-
Illusionist
- Forum Regular
- Posts: 903
- Joined: Mon Jan 12, 2004 9:32 pm
<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>
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>
-
Illusionist
- Forum Regular
- Posts: 903
- Joined: Mon Jan 12, 2004 9:32 pm
-
Illusionist
- Forum Regular
- Posts: 903
- Joined: Mon Jan 12, 2004 9:32 pm
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
Code: Select all
<?php
}
?>