Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

Already on GitHub? Sign in to your account

Zend\Form\View\Helper\FormSelect #3426

isimonov opened this Issue Jan 14, 2013 · 4 comments


None yet
4 participants

In Zend\Form\View\Helper\FormSelect

if (in_array($value, $selectedOptions)) {
    $selected = true;

Marks the selected zero and empty values​​, if you select an empty value. This happens because: '' == 0 and '' == '', so for example you need to fix:

if (in_array((string)$value, $selectedOptions)) {
    $selected = true;

Then: '' != 0 and '' == '' - it should be

Please note this!

The choice of an empty item in Zend\Form\Element\Select is selected also the zero element. For example.
In controller:

$searchForm = new \Zend\Form\Form();
    'type' => 'Zend\Form\Element\Select',
        'name' => 'active',
        'options' => array(
            'label' => 'Active',
            'empty_option' => '',
            'value_options' => array(
                1 => 'Yes',
                0 => 'No',

In template:

<?= $this->formSelect($searchForm->get('active')) ?>

The generated html code:

<select name="active">
    <option value="" selected="selected"></option>
    <option value="1">Yes</option>
    <option value="0" selected="selected">No</option>

Two points are selected, he should have one. I think this is a bug.


rhutchison commented Jan 15, 2013

submit a PR.


Maks3w commented Jan 17, 2013

I remember a bug like this with InArray validator. So I suggest write some common code for this kind of checks on StdLib.

Also is needed to check if $selectedOptions is an array of strings, if not then is needed cast each value to string too

weierophinney added a commit that referenced this issue Jan 22, 2013


weierophinney commented Jan 22, 2013

Fixed with #3509

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment