Zend_Form - Array based elements?

2019-01-11 13:31发布

Using Zend_Form, how would I create form elements like this:

<input type="text" name="element[1]" value="" />
<input type="text" name="element[2]" value="" />
// etc...

2条回答
干净又极端
2楼-- · 2019-01-11 14:04

You can either use subforms:

$form = new Zend_Form();

$subForm = new Zend_Form_SubForm();
$subForm->addElement('Text', '1')
        ->addElement('Text', '2');

$form->addSubForm($subForm, 'element');

Or you should also be able to use setBelongsTo() on the form elements (untested):

$form = new Zend_Form();
$form->addElement('Text', '1', array('belongsTo' => 'element'))
     ->addElement('Text', '2', array('belongsTo' => 'element'));
查看更多
爷、活的狠高调
3楼-- · 2019-01-11 14:19

I contend that setBelongsTo is of substandard quality, as one is unable to set default values. And so, at the present time, there's no reasonable way to achieve your objective.

查看更多
登录 后发表回答