phpzend-formzend-framework2multi-select

MultiSelect in Zend Framework 2


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


Solution

  • 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.