Re: Any PHP equivalent of Macromedia ColdFusion's location tag?
| From: | Justin French | Date: | Wed, 27 Mar 2002 06:04:03 +0000 |
| Subject: | Re: Any PHP equivalent of Macromedia ColdFusion's location tag? | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-90321@lists.php.net to get a copy of this message | ||
Seems like you're getting confused about output verses php code. Let's say
you have a file called "form.php"...
it submits to itself, checking the submitted data. if the form input is
good, you want to do "stuff", then redirect them to a thanks page. if it
isn't, you want to send them back to try again.
Easy.
form.php
---
<?
if(!isset($action))
{
?>
<HTML>
<?
if($problem)
{
echo "there was a problem with your entry, please try again";
}
?>
<!-- form here -->
</HTML>
<?
}
else
{
if($action == "validate")
{
//
// check form input
//
if($input == "valid")
{
// insert stuff into your data base, or do whatever
header("Location: form.php?action=thanks");
// no output to screen
}
else
{
header("Location: form.php?problem=1");
// they're sent back to the form,
// and told there was a problem
// no output to screen
}
}
elseif($action == "thanks")
{
?>
<HTML>
<BODY>
<FONT>Thanks!</FONT>
</BODY>
</HTML>
<?
}
}
?>
---
So, obviously it needs massaging, and none of the code is tested, but it's
the same way I do my forms.
It'd be better if you told them where they went wrong on the form, and there
are lots of ways to streamline the code and make it more modular, but this
should be enough to give you an idea about how you can use the header(), and
at what point you've sent "output" to the browser.
Justin French
--------------------
Creative Director
http://Indent.com.au
--------------------