I am using ZF 1.7.0
For some odd reason I am still struggling to get the
zend_form_element_file element to work properly. The problem I am now
running into is that when I set required to false the getValue of the
file element will give back the name of the last directory of the
destinationPath when I submit the form without selecting a file.
example code:
$destinationPath = '/var/www/example/documents';
$element = new Zend_Form_Element_File('doc');
$element->setLabel('Document:')
->setRequired(false)
->setDestination($destinationPath)
->addValidator('Size', 0, 10485760)
->addValidator('Extension', false, array('pdf','doc','docx'));
$form->addElement($element, 'doc');
// ......
if($form->isValid($this->_request->getPost()) {
if($form->receive()) {
echo $form->getElement('doc')->getValue();
// result: documents
echo $form->employee_cv_file->getFileName();
// result: /var/www/example/documents
}
}
When submitting a form with this element, without selecting/uploading
a document-file will return 'documents' as its value. Is there a
particular reason why this is happening? Is there a way to easily
circumvent this from happening or should I use the isUploaded()
function of the adapter for each file-element?
Thanks for your input!
Regards,
Pieter
没有评论:
发表评论