Re: Re: Variable name as a string

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux