ZF-4879: Multiple equal option values to Zend Form Select elements


Currently, it's not possible to use addMultiOptions to pass an array with equal option values to a Select/MultiSelect form element, because the value has to be stored as the key of the multiOptions array.

in a similar manner to the addMultiOptions option of specifically setting key and value, formSelect should be enhanced to support an array of key/value pairs.

Because I needed a solution now, I created my own ViewHelper to take into account for the same value in different optgroups, like this:

                    $list[] = $this->_build($val, $lab, $value, $disable);

is replaced by

                    if (is_array($lab) 
                        && array_key_exists('key', $lab)
                        && array_key_exists('value', $lab)
                    ) { 
                        $list[] = $this->_build($lab['key'], $lab['value'], $value, $disable);
                    } else {
                        $list[] = $this->_build($val, $lab, $value, $disable);

which requires to prepare the array passed to the viewhelper like ````


My project is hanging on this, and programming around it is a pain for me.

And I can't use this solution because I don't use opt grouping. But I must have this solution applied so I can use same value with different labels. So the users selects right foreign key-number in a database relation with a barcode scan. Why I have this problem is that HP's product number vary up to 3 times on same product, and all labelscans must match to that 1 product.

What about changing how {{Zend_Form_Element_Multi}} stores options? Instead of storing them as one array, it can store the keys as one array and the labels as a separate array. It could also have an {{$_allowDuplicateKeys}} option, perhaps defaulting to false for backwards-compat.

Then {{Zend_View_Helper_FormSelect::formSelect()}} would also have to be refactored slightly, but it's not as straightforward if one wants to avoid changing the method signature. The $options param can't simply be an array($arrayOfKeys, $arrayOfLabels), because currently if an $options element is itself an array, it triggers the ing. Of course one could just add another param on the end, {{array $optionLabels = null}}, and if it's set, $options is interpreted as just the keys, but then it's weird that $listsep is between them. I'll try to think more about this...