Reputation: 8882
I'm trying to work with the data coming in from a form (full of checkboxes, if that matters).
The output of the POST looks like "buzz: on, asdf: on, userid: 1".
if(isset($_POST['userid']))
{
$postedUserID = $_POST['userid'];
foreach ($_POST as $key => $value)
{
switch($key)
{
case "buzz":
$old_services = get_user_meta($postedUserID, 'whatservices', true);
$updated_services = $old_services . " buzz";
update_user_meta($postedUserID, 'whatservices', $updated_services);
break;
default:
echo "Something is wrong.";
}
}
}
I think I'm just confusing myself a bit with the switch and with the key value pairs. How can I have the switch actuate when $_['buzz'] = on?
(The reason I'm using a switch is because this will eventually have a LOT of conditions, >20.)
Upvotes: 0
Views: 83
Reputation: 54841
Maybe you need this:
foreach ($_POST as $key => $value)
{
switch($key)
{
case "buzz":
if ($value == 'on') {
// do something
}
break;
// more cases
}
}
Upvotes: 2