Thursday, February 13, 2014

Setting selected values in multiselect checkbox

I have a multiple select, checkbox type, created with the form helper (Cake 2.0).  I know that to set a selected value, I pass in 'selected' => 'selected_field'. But is there an equivalent to set multiple pre-selected values?  I assumed it was just to pass in an array, but I tried that, and nothing is marked as selected.

I have:

echo $this->Form->select('fieldlist', $listoptions, array('multiple' => 'checkbox', 'selected' => $selectedoptions));

where $selectedoptions is an array like this:
 [0] => field1,
 [1] => field3

$listoptions is the fields:
 [field1] => Label 1
 [field2] => Label 2
 [field3] => Label 3

What am I doing wrong? Thanks for any help!  I know this is pretty basic, but I just can't get my head around it today!!

--
Like Us on FaceBook https://www.facebook.com/CakePHP
Find us on Twitter http://twitter.com/CakePHP
 
---
You received this message because you are subscribed to the Google Groups "CakePHP" group.
To unsubscribe from this group and stop receiving emails from it, send an email to cake-php+unsubscribe@googlegroups.com.
To post to this group, send email to cake-php@googlegroups.com.
Visit this group at http://groups.google.com/group/cake-php.
For more options, visit https://groups.google.com/groups/opt_out.

No comments: