Re: Re: Variable name as a string
| From: | Ross McKay | Date: | Thu, 28 Aug 2008 04:03:52 +0000 |
| Subject: | Re: Re: Variable name as a string | ||
| References: | 1 2 3 4 5 6 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-278853@lists.php.net to get a copy of this message | ||
On Wed, 27 Aug 2008 22:25:44 -0500, Micah Gersten wrote:
>You cannot have anything in the brackets for the name in a checkbox
>group. [...]
Bollocks.
<form action="<?php echo $_SERVER['SCRIPT_NAME']; ?>"
method="post">
<p>option 1 - colour: <input type="text"
name="options[colour]"/></p>
<p>option 2 - flavour: <input type="text"
name="options[flavour]"/></p>
<p>option 3 - size: <input type="text"
name="options[size]"/></p>
<p><input type="submit"/></p>
</form>
<?php
function test() {
$colour = $_POST['options']['colour'];
echo "<p>colour: $colour</p>\n";
$flavour = $_POST['options']['flavour'];
echo "<p>flavour: $flavour</p>\n";
$size = $_POST['options']['size'];
echo "<p>size: $size</p>\n";
}
?>
NB: no quotes around array key!
I found this very handy for having variable product options on a simple
shopping cart.
--
Ross McKay, Toronto, NSW Australia
"The lawn could stand another mowing; funny, I don't even care"
- Elvis Costello