In normal html, we could have an array field like person[]
<input name="person[]" type="text" />
<input name="person[]" type="text" />
<input name="person[]" type="text" />
As far as I know, Zend_Form doesn't have that. I read another answer that suggested it could be done using a decorator that would add the []
at the right place. This is the code for that specific question
$html = ''; // some code html
$i = 0;
foreach ($element->getMultiOptions() as $value => $label){
$html .= '<input type="checkbox" '
. 'name="'.$element->getName().'[]" '
. 'id="'$element->getName()'-'.$i.'" '
. 'value="'.$value.'" />';
$i++;
}
return $html;
This looks like a good start, but I wonder if using a decorator is enough. The values that get returned back have to be read correctly and delivered to the server, then validated on the server side. So is a decorator the wrong idea? Would a custom element make more sense here? I haven't seen a good example that shows how this can be done.