Zend_Form array names and empty element names

I want to do:

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

but Zend_Form_Element requires a name (string), so I need to do:

$this->addElement('text', '1', array(
    'belongsTo' => 'foo'
));

$this->addElement('text', '2', array(
    'belongsTo' => 'bar'
));

but conclusion:

<input id="foo-1" type="text" value="" name="foo[1]" />
<input id="bar-2"  type="text" value="" name="bar[2]" />

I can also accept the output, for example:

<input id="foo-1" type="text" value="" name="foo[1]" />
<input id="bar-1"  type="text" value="" name="bar[1]" />

but Zend_Form_Element overwrites the elements with the same name

Is there a way to do what I need?

+5
source share
2 answers

For multiple values:

$foo = new Zend_Form_Element_Text('foo');
// Other parameters
$foo->setIsArray(TRUE);
$this->addElement($foo);

Creates: name="foo[]"

-

If you are looking for the given keys, for example name="foo[bar]", use:

$bar= new Zend_Form_Element_Text('bar');
// Other parameters
$bar->setBelongsTo('foo');
$this->addElement($bar);

-

Tested on ZF 1.11.5

+7
source

MyFooForm Zend_Form {         public function init() {         $ fullNameOpts = (                  '' = > ,                  '' = > 'FULLNAME',                  'IsArray' = > ,                  'validators' = > array (array ('stringLength', false, array (1, 250)))         );    $ this- > addElement ('text', 'fullName', $fullNameOpts);    // ,         }    }

<dd id="fullName-element"><input type="text" class="inputAccesible" value="" id="fullName"name="fullName[]"></dd>

Element.php, , 512 "isArray". zend_form, crossValidation , , . , , , , subForms , , .

Zf 1.10.

0

All Articles