views:

1594

answers:

1

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...
+3  A: 

You can either use subforms:

$form = new Zend_Form();
$subForm = 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'));
Stefan Gehrig
Second, form seems to be more clean and straight-forward, and works ok (tested).
Victor Farazdagi
If anyone has issues with validation, getValue() etc - see this *resolved* ticket on ZF tracker: http://framework.zend.com/issues/browse/ZF-2563
Victor Farazdagi