MultiSelect in Zend Framework 2

bogatyrjov picture bogatyrjov · Nov 11, 2012 · Viewed 12.7k times · Source

There was a Zend_Form_Element_Multiselect in Zend Framework 1.12. How to achieve the same result in Zend Framework 2.0 ? I only see Zend\Form\Element\MultiCheckbox and Zend\Form\Element\Select

Answer

bogatyrjov picture bogatyrjov · Nov 11, 2012

Ok, I found the answer myself and it wasn't easy to read out of the official documentation, rather an experiment solution :

        $this->add(array(
            'type' => 'Zend\Form\Element\Select',
            'attributes' => array(
                'multiple' => 'multiple',
            ),
            'name' => 'langs',
            'options' => array(
                'label' => 'langs',
                'value_options' => array(
                    '0' => 'French',
                    '1' => 'English',
                    '2' => 'Japanese',
                    '3' => 'Chinese',
                ),
            ),
        ));

Just add

        'attributes' => array(
            'multiple' => 'multiple',
        ),

to your setup.