My Edit view file has a set of checkboxes. I have managed to retrieve the selected checkbox values from the database, and want to mark these as selected in the view file.
Edit view file
<div class="col-md-12">
<?= $this->Form->label('category','Pick Categories');?>
<?= $this->Form->select('category', $options,['multiple'=>'checkbox', 'required'=>'false', 'label'=>'Category','class'=>'col-md-12','selected'=>$catSel]); ?>
</div>
$options is
$options = ['A'=>'Val1',
'B'=>'Val2',
'C'=>'Val3',
'D'=>'Val4',
'E'=>'Val5'];
$catSel has been set in my controller and is returning the correct values. I checked with print_r(), shown below:
Array ( [0] => 1 [1] => 3 )
I have also tried directly entering the selected value
<?= $this->Form->select('shop_category', $options,['multiple'=>'checkbox', 'required'=>'false', 'label'=>'Shop Category','class'=>'col-md-12','selected'=>[1,3]]); ?>
I have also tried sending in $catSel as
Array ( [0] => A [1] => C )
None of this is working. Not sure why. I haven't been able to find any solution to this anywhere, apart from the set 'selected' as array of selections. Any help will be appreciated.