Issues

ZF-4411: Problems with Validating of multiple File Elements

Issue Type: Bug Created: 2008-09-29T03:12:00.000+0000 Last Updated: 2008-11-13T14:10:30.000+0000 Status: Resolved Fix version(s): - 1.7.0 (17/Nov/08)

Reporter: malt (malt) Assignee: Thomas Weidner (thomas) Tags: - Zend_File_Transfer

Related issues: - ZF-4589

Attachments: - demo.php

Description

In a form with multiple file elements each with multiple validators, i get wrong or no error messages, although i did select a file, which should fail the validation. I attached a small sample application. To verify the problem just upload wrong files in both file elements or only in one. Code used is from latest trunk.

To fix this behaviour i made 2 small changes:

<pre class="highlight">
public function isValid($value, $context = null) {
...
    if($adapter->isValid($this->getFullyQualifiedName())) {
          $this->_validated = true;
          return true;
    }
    // added: pass the errors to the form element error properties
    if($adapter->hasErrors()) {
         $this->addErrors($adapter->getMessages());
    }
    $this->_validated = false;
    return false;
}

I am not sure why the error properties of the form element base class are not used for the error messages. However the messages in the adapter wont be touched by this, in case someone needs them.

This steps also make it necessary to remove the overridden getMessages(), getErrors(), hasErrors() functions, otherwise you wont get the correct error messages for each form element.

The second change:

<pre class="highlight">
public function isValid($value){
...
            switch($content['error']) {
                case 0:
                    if (!is_uploaded_file($content['tmp_name'])) {
                        $this->_error(self::ATTACK);
                   // added: no error found, but unset the message array anyway, so the function can return true later;
                   //  this wont happen if there was a file element before with an error
                    }  else {
            $this->_messages = array();
                   } 
                  break;
...

This fixed the problem for me, but i know that does not mean it should be added right now without further testing. However i need the file upload component in a time critical project, so i have to keep going. I hope i made the problem clear and it can be verified.

Comments

Posted by malt (malt) on 2008-09-29T03:13:45.000+0000

Same sample application as in ZF-4386.

Posted by Thomas Weidner (thomas) on 2008-10-26T08:07:46.000+0000

Should be fixed with trunk.

Posted by Wil Sinclair (wil) on 2008-11-13T14:10:30.000+0000

Changing issues in preparation for the 1.7.0 release.

Have you found an issue?

See the Overview section for more details.

Copyright

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

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

Contacts