Reputation: 5437
I'm having the following code to render a zend form file input
$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.');
All is working fine but when I leave the file filed empty then, it does not work. The zend form validator returns an empty error string message.
What wrong am doing??
Upvotes: 4
Views: 1014
Reputation: 13
This is my first answer, this might be right because, I also once had the similar problem, I saw that you have used both
$pd_photo->setRequired(false);
$pd_photo->setAllowEmpty(true);
In this case you should also define for 'NotEmpty' => 'false'
Try defining the above property for file element this should solve your problem, mine was resolved by this.
Upvotes: 1