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

Issue Type: Bug Created: 2011-06-22T17:11:10.000+0000 Last Updated: 2011-07-28T13:29:28.000+0000 Status: Resolved Fix version(s): - 1.11.10 (04/Aug/11)

Reporter: Natalia Tichshenko (leffe) Assignee: Thomas Weidner (thomas) Tags: - Zend_Form

  • Zend_Validate_File

Related issues: Attachments:


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… 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

<pre class="highlight"> 
echo $this->form;

in view (index.phtml)

But when I want to call form elements separately, like

<pre class="highlight">
$element = $this->elements[0]; // file element
echo $this->form->$element->renderFile();

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

or simply

<pre class="highlight">
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:

<pre class="highlight">
public function init() 
array('HtmlTag', array('tag' => 'div')),
$this->setAttrib('enctype', 'multipart/form-data');
$file = new Zend_Form_Element_File('file');
$file->addValidator('Extension', false, 'txt,doc,docx,pdf');
$submit = new Zend_Form_Element_Submit('submit');

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


Posted by Kim Blomqvist (kblomqvist) on 2011-06-23T15:05:08.000+0000

adding code tags

Posted by Maxim Postoronca (max4ever) on 2011-07-08T14:28:03.000+0000

have you tried… ?

Posted by Thomas Weidner (thomas) on 2011-07-28T13:29:28.000+0000

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.

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.