CakePHP 2.0 Select the form selected by Mulitple

So, I have this dropdown menu where you can select multiple values. Now let's say I want to edit my information and create a drop-down menu with several selected values. Trying to figure out how this happens, but no results.

Let's say I have:

$selected = array(3, 4); $options = array(1,2,3,4); echo $this->Form->select('Attendees', $options,array('multiple' => true, 'selected' => $selected)); 

I used this code but nothing is selected.

+4
source share
1 answer

I found a way well, it should look like this:

 $selected = array(2, 3); $options = array(1, 2, 3, 4); echo $this->Form->input('Attendees', array('multiple' => true, 'options' => $options, 'selected' => $selected)); 

It will display:

  • 1
  • 2
  • 3 verified
  • 4 verified

The selected $ checks the key index of each item, not the value itself.

+5
source

Source: https://habr.com/ru/post/1435022/


All Articles