Issues

ZF-11501: $form->isValid($_POST) returns false when calling form elements one by one

Description

I do not know if it's a bug, and I started to work with Zend Framework it's been couple of months only, so I am sorry if it's a trivial question. I've been having a trouble with file upload lately and did quite a lot of research about it. I used this tutorial http://akrabat.com/zend-framework/… to create my file upload, I added certain things like filter(to rename the file) etc, and I needed multiple file upload so I added necessary changes for this as well as to send the uploaded files as attachments by email. Everything works fine when I call the form as

 
echo $this->form;

in view (index.phtml)

But when I want to call form elements separately, like


$element = $this->elements[0]; // file element
echo $this->form->$element->renderFile();

$element = $this->elements[1];//submit
echo $this->form->$element->renderViewHelper();

or simply


echo $this->form->file;
echo $this->form->submit;

The form elements are displayed correctly, but $form->isValid($_POST) returns false and I get an empty array on calling $form->getMessages();

The reason i need to call upload elements one by one is that upload has to be a part of a bigger form for people to fill in and I should have a control over each element of the form.

I have a function getElementsNames() that returns an elements' names array and in controller I call $this->view->elements = $this->view->form->getElementsNames();

I thought the problem could be in decorators, but I do not reset decorators or do clearDecorators();

here is my form:


public function init() 
{         
$this->setName('upload');
$this->setMethod("post");
$this->setDecorators(
array(
'FormElements',
array('HtmlTag', array('tag' => 'div')),
'Form'
}
);
$this->setAttrib('enctype', 'multipart/form-data');
$file = new Zend_Form_Element_File('file');
$file->setName("file");
$file->setDestination('./uploads/');
$file->addValidator('Extension', false, 'txt,doc,docx,pdf');
$file->setMultiFile(3);
$file->setValueDisabled(true);
$this->addElement($file);
$submit = new Zend_Form_Element_Submit('submit');
$submit->setLabel('Upload');
$this->addElement($submit);
}

I apologize if my post is not very concise, it the first time I actually post something. Thankyou for your time.

Comments

adding code tags

Note that acrabats tutorial is using ZF 1.5 which is a little bit outdated.

This issue seems to be a coding request and no bug report. For generic help on coding issues please ask at ZFs mailinglist. For details on how Zend_Form and its elements work you can refer to ZFs documentation.

When you have found a bug within ZF feel free to reopen this issue. Please give additional reproduceable informations in this case.