开发者

Add many select elements with [] in name

开发者 https://www.devze.com 2023-01-16 20:01 出处:网络
I want to be able to add to Zend_Form many Zend_Form_Element_Select. I\'ve got some loop in My_Form_Selects extends Zend_Form with

I want to be able to add to Zend_Form many Zend_Form_Element_Select.

I've got some loop in My_Form_Selects extends Zend_Form with

$element = $this->createEleme开发者_如何学Gont('Select', 'element[]');
$this->addElement($element);

but it creates only one select element (Zend_Form ignores [] in element's name).

How should I do this ?


Have you tried:

$foo = new Zend_Form_SubForm();
$foo->setElementsBelongTo('foo')
    ->setElements(array(
        'bar' => 'text',
        'baz' => 'text'
    ));
echo $foo;

which results in HTML something like:

<input type="text" name="foo[bar]" id="foo.bar" value="" />
<input type="text" name="foo[baz]" id="foo.baz" value="" />

via

From the manual:

Zend_Form::setIsArray($flag): By setting the flag TRUE, you can indicate that an entire form should be treated as an array. By default, the form's name will be used as the name of the array, unless setElementsBelongTo() has been called. If the form has no specified name, or if setElementsBelongTo() has not been set, this flag will be ignored (as there is no array name to which the elements may belong).

You may determine if a form is being treated as an array using the isArray() accessor.

Zend_Form::setElementsBelongTo($array): Using this method, you can specify the name of an array to which all elements of the form belong. You can determine the name using the getElementsBelongTo() accessor.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号