Zend Form file input set required false not working

I have the following code to render the input of a zend form file

$pd_photo = new Zend_Form_Element_File('photo');
$pd_photo->setDestination(APPLICATION_PATH . '/../uploads');
$pd_photo->setRequired(false);
$pd_photo->setAllowEmpty(true);
$pd_photo->addValidator('Count', false, 1);
$pd_photo->addValidator('Size', false, 2097156672);
$pd_photo->addValidator('Extension', false, 'jpg,jpeg,png,gif,bmp');

$pd_photo->getValidator('Count')
         ->setMessage('You can upload only one file');
$pd_photo->getValidator('Size')
         ->setMessage('Your file size cannot upload file size limit of 1 MB');
$pd_photo->getValidator('Extension')
         ->setMessage('Invalid file extension, only valid image extensions are 
                      (jpg, jpeg, png, gif, bmp) allowed.');

Everything works fine, but when I leave an empty file, it does not work. The zend form validator returns an empty error line message.

What is bad to do?

+4
source share
1 answer

This is my first answer, it may be correct because, I also had a similar problem, I noticed that you used both

$pd_photo->setRequired(false);
$pd_photo->setAllowEmpty(true);

In this case, you should also define for 'NotEmpty' => 'false'

Try to define the property above for the file element, this should solve your problem, mine was solved by this.

+1
source

Source: https://habr.com/ru/post/1543063/


All Articles