ZF-4388: Zend_File breaking on isValid

Issue Type: Bug Created: 2008-09-26T05:29:34.000+0000 Last Updated: 2008-10-10T14:41:46.000+0000 Status: Resolved Fix version(s): - 1.6.2 (13/Oct/08)

Reporter: Martin Shwalbe (vsplash_martin) Assignee: Thomas Weidner (thomas) Tags: - Zend_File_Transfer

Related issues: - ZF-4386



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']);


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);

                             ->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);

<pre class="literal"> 
                   ->addValidator('Count', false, 1)     // ensure only 1 file
                   ->addValidator('Size', false, 102400) // limit to 100K
                   ->addValidator('Extension', false, $this->CONFIG->images->allowed_images)

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


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

<pre class="highlight">

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.

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.