Zend Framework

Zend_File breaking on isValid

Details

  • Type: Bug Bug
  • Status: Resolved Resolved
  • Priority: Major Major
  • Resolution: Fixed
  • Affects Version/s: None
  • Fix Version/s: 1.6.2
  • Component/s: Zend_File_Transfer
  • Labels:
    None

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

Issue Links

Activity

Hide
Thomas Weidner added a comment -

ignoreNoFile does not work for ZF 1.6

Please give code for reproduction

Show
Thomas Weidner added a comment - ignoreNoFile does not work for ZF 1.6 Please give code for reproduction
Hide
Thomas Weidner added a comment -

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.

Show
Thomas Weidner added a comment - 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.
Hide
Thomas Weidner added a comment -

I see no problem at all.

When you add a

->setRequired(false)

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

Show
Thomas Weidner added a comment - I see no problem at all. When you add a
->setRequired(false)
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
Hide
Thomas Weidner added a comment -

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.

Show
Thomas Weidner added a comment - 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.
Hide
Thomas Weidner added a comment -

Closing issue due to non-response.

Show
Thomas Weidner added a comment - Closing issue due to non-response.

People

Vote (0)
Watch (0)

Dates

  • Created:
    Updated:
    Resolved: