As the example below shows how to call on the fields, my question is how to call a multiple checked checkbox. please give me an example
$merge_vars = array('FNAME'=>'Test', 'LNAME'=>'Account',
'GROUPINGS'=>array(
array('name'=>'Your Interests:', 'groups'=>'Bananas,Apples'),
array('id'=>22, 'groups'=>'Trains'),
)
);
I get a solution for this.
To get the multiple checked checkbox you need to do a looping and set it in array then change the array to a string.
if(!empty($_POST['listbox']))
{
foreach($_POST['listbox'] as $value => $val)
{
$values[] = $val;
}
$groups = implode(",", $values);
}
then set it in the merge_vars
$merge_vars = array('FNAME'=>'Test', 'LNAME'=>'Account',
'GROUPINGS'=>array(
array('name'=>'Your Interests:', 'groups'=> $groups)
)
);
Hope it helps :)
You must put the separated by commas but you must ensure that they have commas escaped:
$groups = array();
if(!empty($_POST['listbox'])) {
$interests = array();
foreach($_POST['listbox'] as $interest)
{
$interests[] = str_replace(',', '\,', $interest);
}
$groups = implode(",", $interests);
}
$merge_vars = array(
'FNAME'=>'Test',
'LNAME'=>'Account',
'GROUPINGS'=> array(
array(
'name'=>'Your Interests:',
'groups'=> $groups
),
array(
'id'=>22,
'groups'=>'Trains'
)
)
);
If you are sure that the interest string do not have commas you can just do this:
$groups = implode(',', $_POST['listbox']);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With