Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Zend_Form - Array based elements?

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...
like image 911
leek Avatar asked Jan 02 '09 02:01

leek


1 Answers

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'));
like image 103
Stefan Gehrig Avatar answered Oct 13 '22 23:10

Stefan Gehrig