Re: easier than switch
| From: | Paul Chvostek | Date: | Mon, 04 Aug 2003 22:55:11 +0000 |
| Subject: | Re: easier than switch | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-158204@lists.php.net to get a copy of this message | ||
On Mon, Aug 04, 2003 at 11:19:42PM +0100, skate wrote:
>
> i have several forms on one page, they all submit a different variable, i then want to set one
> variable depending on that... okay, now i'm confusing myself, lets try explain it with some
> code...
>
> if(isset($_POST))
> {
> $type = $_POST['news'] || $_POST['dreams'] || $_POST['storys']
> || $_POST['words'] || $_POST['chat'];
> }
You have a single page, containing multiple forms, all of which share
the same action? What about putting a hidden variable into each form to
provide an authoritative reference to which form was posted? Then, if
processing unique to each form can be done with:
if ($_POST['func']=="thisone") {
// fooblah
} else
if ($_POST['func']=="thatone") {
// barblah
} else
if ($_POST['func']=="another") {
// otherblah
} else {
die("Form hacking detected");
}
And you can do things with the content of $_POST['func'], like this:
$typelist=array(
'thisone' => "This is one",
'thatone' => "That is one too",
'another' => "Another one here",
);
$type=$typelist[$_POST['func']];
Is that long the lines of what you're looking for?
--
Paul Chvostek <paul@it.ca>
it.canada http://www.it.ca/
Free PHP web hosting! http://www.it.ca/web/