Search code examples
phpzend-frameworkzend-form-element

using same zend_form_element multiple times


I'm building a Zend_Form.Having:

$file=new Zend_Form_Element_File('file');
$file->setDescription('upload a picture:')
->setDestination(myPath);
$file->class="media[]";
$file->setDecorators(array(
'File',
array('Description',array('placement'=>'PREPEND','tag'=>'')),
array('HtmlTag',array('tag'=>'span','class'=>'myclass'))
));

I can't add the same element multiple times to the form with:

$form->addElements(array($file,$file));

Do I need to create a custom form_element_file class so that I can register the exact same element with the form more than once?How?

thanks

Luca


Solution

  • If you want to have more than one identical Zend_Form_Element_File elements in your form you can just setup setMultiFile method, e.g.

    $file=new Zend_Form_Element_File('file');
    $file->setMultiFile(2);
    $form->addElement($file);
    

    Hope this helps.