views:

54

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=""/>
A: 

Use a SubForm:

$form = new Zend_Form;
$subForm = new Zend_Form_SubForm('SubForm', 'element');
$subForm->addElements(array(
    $subForm->createElement('Text', '0'),
    $subForm->createElement('Text', '1'),
));
$form->addSubForm($subForm, 'element');

I'm sure this can be written with array notation somehow too.

Gordon
Array notation: http://zendframework.com/issues/browse/ZF-2563#comment-18830-open
Ashley