0
votes

Is there an example of how I can use the select mulitoptions using the Zend Forms in Zend Franework 2. I have got a requirement where I need to populate the selection box with the data from database and give the user the option to select multiple options, so that when the user selects his choice of options and submits it, then I want to store it in another table. I just described my requirement, I know how all these things work with normal PHP, MySQL and HTML. Since I dived into the Zend Framework 2 very recently, searched the Zend Framework 2 offcial website and found examples for using 'Select', but nothing for select multioptions. In case if some one can guide me how to approach this issue, their efforts would be appreciated.

1

1 Answers

0
votes

If I understand your question correctly, I would start by looking at the Zend\Form\Element\Collection element class.

There is quite a good tutorial/resource that uses the Collection element: http://packages.zendframework.com/docs/latest/manual/en/modules/zend.form.collections.html

Instead of using an element's class name to define the target_element, create an instance of Zend\Form\Element\Select and populate the dropdown values using setValueOptions() and pass this as the target_element.

The tutorial uses JavaScript to add new items to the collection.