ZF-4411: Problems with Validating of multiple File Elements

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:


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:


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

Same sample application as in ZF-4386.

Should be fixed with trunk.

Changing issues in preparation for the 1.7.0 release.