Please help.
I am trying to dynamically name my checkboxes using php. I am using POST.
The problem I am running in to is $element is not working. The results of $_POST
does not show any checkboxes.
Thanks in advance for the help.
foreach(array_keys($cart_array) as $element)
{
print "<input type = 'checkbox' checked name = '{$element}' />";
}
But something like
foreach(array_keys($cart_array) as $element)
{
print "<input type = 'checkbox' checked name = '$element}' />";
}
works just fine. Notice the missing { near $element}. This code would show which checkboxes are
on!! The printed array would have an extra “}”
Array
(
[Tomato_and_Cheese_small] => on
[Tomato_and_Cheese_small}] => 1
[Tomato_and_Cheese_large] => on
[Tomato_and_Cheese_large}] => 1
)
ps. there are other inputs like text that get posted to $_POST just fine.
The print_r($cart_array) works fine too.
The browser sends the value of radio buttons only when they are checked.
Also, each radio button must have the same name (if you want to user to be able to check only one of them). Only the value changes:
POST this and check the value of
$_POST['checked_items']