I'm working on Zend Framework 1.11.12 version. In my add form where we've to put file upload (for photo upload) field and it has few validations as required, file extensions and size specific criteria mentioned as below, which is declared under my zend form:
// part of my form class (Default_Form_Photo::init)
$photo = new Zend_Form_Element_File('photo', '', array('required' => true));
$photo->setLabel('Photo')
->setDestination('/var/www/zendframework/public/uploads/');
// ensure its mandatory
#$photo->addValidator('required', true);
// ensure only one file
$photo->addValidator('Count', false, array('min' => 1));
// max 2MB
$photo->addValidator('Size', false, 2097152)
->setMaxFileSize(2097152);
// only JPEG, PNG, or GIF
$photo->addValidator('Extension', false, 'jpg,jpeg,png,gif');
$photo->setValueDisabled(true);
$this->addElement($photo, 'photo');
Now I have taken a hidden field, for edit page which will return me current image name, if no new image uploaded:
// hidden element for edit time photo save
$this->addElement('hidden', 'photo_uploaded', array( ));
I set this hidden element value from controller by $form->photo_uploaded->setValue($result['photo']).
Now the problem is: when user edit information, it does not allow saving because the file upload field is blank as no new image uploaded, but in my case have to use existing current image, which I am passing from hidden element to my controller.
So validation causes problem here, any idea how can i remove validation for my edit page where users do not have to upload new image every time, they are editing information.
Earliest response will be appreciated.
Thanks !