ZF-6032: problem uploading file in a subform

Issue Type: Bug Created: 2009-03-14T10:55:09.000+0000 Last Updated: 2009-03-24T13:03:40.000+0000 Status: Resolved Fix version(s): - 1.8.0 (30/Apr/09)

Reporter: Karla Heredia (karla) Assignee: Thomas Weidner (thomas) Tags: - Zend_File_Transfer

Related issues: Attachments:



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);


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();
        $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


Posted by Thomas Weidner (thomas) on 2009-03-14T11:03:29.000+0000

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.

Posted by Karla Heredia (karla) on 2009-03-15T08:01:07.000+0000

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.


Posted by Thomas Weidner (thomas) on 2009-03-15T09:44:02.000+0000

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).

Posted by Thomas Weidner (thomas) on 2009-03-24T13:03:39.000+0000

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

Have you found an issue?

See the Overview section for more details.


© 2006-2018 by Zend, a Rogue Wave Company. Made with by awesome contributors.

This website is built using zend-expressive and it runs on PHP 7.