In normal html, we could have an array field like person[]
I think that ZF does not allow for creation of individual input text fields named person[]
, although you could do it for the whole form or a subform. However, it allows for something similar. Specifically, you could create fields named person[0]
, person[1]
, etc.
To do this, you could do the following:
$in1 = $this->createElement('text', '0');
$in2 = $this->createElement('text', '1');
$in1->setBelongsTo('person');
$in2->setBelongsTo('person');
This way you could normally attach your validators, filters, etc. to $in1 or $in2 and they would work as expected. In your action, after form validation, you could get an array of the person's input text fields as:
$values = $yourForm->getValues();
var_dump($values['person']);
Interestingly, the following will NOT work:
$in1 = $this->createElement('text', 'person[0]');
$in2 = $this->createElement('text', 'person[1]');
Hope this will help you.