Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Zend Framework 1.12 select element - name array issue

When using Zend_Form_Element_Select in conjunction with setIsArray for some reason Zend Framework 1.12 assumes that you want a multiple select. This seems like a strange behavior of the framework, so I'm think there must be a workaround or another option I'm just not setting.

For example if I use the following code:

$element = $this->getElement('element');
$element->setIsArray(true)
        ->setMultiOptions(array('a' => 'A'));

I get the following output:

<select name="element[]" id="element" multiple="multiple">
<option value="a" label="A">A</option>
</select>

When I want the desired output:

<select name="element[]" id="element">
<option value="a" label="A">A</option>
</select>

i.e. I don't want multiple="multiple"

I have looked into work arounds for this problem, but I don't feel they're appropriate for such a simple problem like adding brackets to the name of your form element. At this point I'm thinking of using jquery to just remove this multiple attribute on page load, but that's really hacky and can't imagine Zend Framework would be working this way.

Does anyone know how to do this using the code example above? I don't want to instantiate a new instance of zend form select, or addElement because one was already established.

like image 494
jsteinmann Avatar asked Feb 17 '26 08:02

jsteinmann


1 Answers

There is a very similar thread at ZF Issue tracker, did you try the suggested workaround?

$element = new Zend_Form_Element_Select('selectbox', array('multiple' => false ));
$element->setIsArray(true);
like image 87
axel.michel Avatar answered Feb 19 '26 23:02

axel.michel



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!