ZF-6032: problem uploading file in a subform

Description

Hello

My problem is: I have included twice a subform type Zend_Form in a form, the subform has a file element, so appear twice the file element with different id, if I fill both subforms files are uploaded but If I fill just one subform (anyone) the files is not uploaded. it is the source in main form:

$this->addSubForm(new PhotoSubForm(array('formId'=>'1')),'PhotoSubForm1',4); 
$this->addSubForm(new PhotoSubForm(array('formId'=>'2')),'PhotoSubForm2',5); 

it is the source in my Controller:

if ($form->isValid($formData))
{
    $subForm1 = $form->getSubForm('PhotoSubForm1'); 
    $photo = Photos::getInstance()->photoRow($subForm1,1); 
    $subForm2 = $form->getSubForm('PhotoSubForm2');
    $photo2 = Photos::getInstance()->photoRow($subForm2,2);

    $this->_redirect('admin/partners/list');
}

my photoRow function:

public function photoRow($form,$formId)
{
    $file = 'file'.$formId ;
    if ($form->$file->isUploaded())
   {
        $path= ROOT_DIR.'/public/images/countries';
        $adapter = $form->$file->getTransferAdapter();
        $adapter->setDestination($path);
        $fileName = basename($form->$file->getFileName());
       if (!$adapter->receive())  // if I fill just one subform enter to the if statement.
       {
           $messages = $adapter->getMessages();
           echo implode("\n", $messages);
       }

       .
       .
       .
  }

sorry for my english I hope that someone can help me !!! thanks

Comments

According to the manual and the API documentation file upload elements must not have the same name within the same form including their subform.

Having 2 file elements named the same leads one overwriting the other.

Hello Tomas Thanks for the comment, I want to add, that the files fields appear with differents names and ids, I have added these lines in my controller when I instanced the main form:

$form->setSubFormDecorators(array('FormElements')); because before, it don't enter to " if ($form->isValid($formData))" statement, now it enter but ocurred the problem that I'm posting.

Thanks.

According to the FAQ and the manual the file element does not work when you delete / erase the "files" decorator from it. The same is guilty for images, captcha and all other decorators which have own default decorators.

When using setDecorators you have to add the needed default decorators, otherwise the elements are not rendered correct (rendering !== visibility).

Not an issue due to deleted/overwritten file decorator. Within trunk a warning is triggered in such a case whe nthe element is rendered.