ZF-4388: Zend_File breaking on isValid
Description
I created a form with a File element which is set to not required
After submitting the form i received Validation Error "File '' not found"
In Zend_File_Abstract on line ~580 if ($this->_options['ignoreNoFile'] and (isset($fileerrors['fileUploadErrorNoFile']))) { unset($fileerrors['fileUploadErrorNoFile']); }
Here it is still continuing to validate; After changing this to if ($this->_options['ignoreNoFile'] and (isset($fileerrors['fileUploadErrorNoFile']))) { unset($fileerrors['fileUploadErrorNoFile']);
break;
}
Validation was working as expected.
I didnt find where to add a new Comment so i am editing this issue. I am using the Zf trunk.
class Form_Profile extends Cms_Form { public function init() { $Language = Zend_Registry::get('language');
/* Create Form Elements */
$UploadLogo = $this->createElement('file', 'UploadLogo');
/* Add Labels */
$UploadLogo ->setLabel($Language->label->UploadLogo);
$UploadLogo->setDestination('./upload/company_logos/image')
->addValidator('Count', false, 1) // ensure only 1 file
->addValidator('Size', false, 102400) // limit to 100K
->addValidator('Extension', false, 'jpg,png,gif'); // only JPEG, PNG, and GIFs
/* Add Elements to Object */
$this ->addElement($OldImage);
}
}
Cms_Form is extending the Zend_Dojo_Form Language is just an ini file where i am keeping my messages and config is also ini
In the controller i am using
if ($this->_request->isPost()) { $formData = $this->_request->getPost();
if ($form->isValid($formData)) { // here i am getting the message "File '' not found"
.... processing the data
if($form->UploadLogo->receive()) {
.... saving the file to database changing the name etc....
}
}
}
file not found is comiing as a validation message after submitting and not uploading a file
Added setRequired(false);
$UploadLogo->setDestination($this->CONFIG->paths->company_logo)
->addValidator('Count', false, 1) // ensure only 1 file
->addValidator('Size', false, 102400) // limit to 100K
->addValidator('Extension', false, $this->CONFIG->images->allowed_images)
->setRequired(false);
After calling isValid receiving the Validation Message "File '' not found";
The ignoreNoFile option is set on the Adapter as expected but it is continuing to Validate and assigning error messages in the Zend_File_Adapter_Abstract
Comments
Posted by Thomas Weidner (thomas) on 2008-09-26T05:41:46.000+0000
ignoreNoFile does not work for ZF 1.6
Please give code for reproduction
Posted by Thomas Weidner (thomas) on 2008-09-26T06:10:13.000+0000
setRequired is a option of Zend_Form. Zend_File_Transfer does not know what you set to Zend_Form. If you know that a file can be optional you have to set the option "ignoreNoFile" on the adapter.
Posted by Thomas Weidner (thomas) on 2008-09-26T06:27:47.000+0000
I see no problem at all.
When you add a
to the file element the validation is ignored as it's expected.
The file element even adds the "ignoreNoFile" Option for you on the adapter. Just add this single line to your code and all works perfect
Posted by Thomas Weidner (thomas) on 2008-09-26T08:39:10.000+0000
Works on my side with your code and the additional line. It returns no validation failure.
Maybe simply a broken file ? Update your repository and look again.
Posted by Thomas Weidner (thomas) on 2008-09-28T08:17:52.000+0000
Closing issue due to non-response.