I'm trying to populate a set of checkboxes based on stored form data. Unfortunately, the isSelected element only seems to return false. Here's the code:
if($field['type'] == 'checkbox'){
$inputs = $field['inputs'];
$count = '0';
foreach($inputs as $input){
if(($user_meta[$input['id']] !== '') && (isset($user_meta[$input['id']]))){
$select = true;
}
else{
$select = false;
}
$field['choices'][$count] = array(
'text' => $field['choices'][$count]['text'],
'value' => $field['choices'][$count]['value'] ,
'isSelected' => $select );
var_dump($select);
var_dump($field['isSelected']);
$count = $count + '1';
}
}
The var_dump
of $select
correctly returns boolean true
and false
values where it should. But the isSelected
element always returns an empty string. This is true even when I replace the $select
variable with a hardcoded true value, or use 1 and 0 instead of true and false.
I'm sure I'm missing something very basic, but I've had no luck finding a solution so far. I'd be grateful for any help!
Edit
Thanks to @Barmar I have a little more information on the problem. It's failing when I try to assign a value to $field['choices'][$count]['isSelected']. The log shows "PHP Notice: Indirect modification of overloaded element of GF_Field_Checkbox has no effect". Unfortunately, I can't see why that would be a problem here, as from what I can tell that error normally comes from using __get/set methods which I'm not actually making use of in this case. I also tried solutions suggested in "Indirect modification of overloaded element of SplFixedArray has no effect" to no avail. Is there some kind of setting or configuration that might be preventing this assignment?