How to add select fields in Zend Framework 2.5

In this tutorial I will explain how to add select fields in Zend Framework 2.5. I have also created a video where you can see how it works. Today I will explain how to add a static select field, but in next weeks I will make another tutorial where I will speak how to create dynamic select fields in Zend Framework 2.5.

So, if you want to add a select field in Zend Framework 2.5, you must only add this code:

$this->add(array(
'type' => 'Zend\Form\Element\Select',
'name' => 'language',
'options' => array(
'label' => 'Which is your mother tongue?',
'value_options' => array(
'0' => 'French',
'1' => 'English',
'2' => 'Japanese',
'3' => 'Chinese',
),
)
));

in your form file.

Next, in your view file, you must add this code:

echo $this->formRow($form->get('language'));

As you might see, its very simple!

Video Tutorial:









Leave a Comment