2010年3月31日星期三

[fw-mvc] Problem validating file upload form field

Dear All,

I have spend too long on this and am getting nowhere. Any help is
appreciated.
Thank you in advance.

Problem:
My optional file upload field always fails the isValid() checks, so no file
gets uploaded, however, the system does not throw any error and attaches no
error message to the file upload field.

Details:

I have a form which works perfectly fine and is controlled by this
controller code:
$request = $this->getRequest();

$updateForm = new Admin_Form_UpdateForm(array(
'action' =>
$request->getBaseUrl().'/admin/account/update'));
$updateForm->setMethod( 'POST' );
$updateForm->setAttrib('enctype', 'multipart/form-data');
$updateForm->setDecorators(array(
array('ViewScript', array('viewScript' =>
'forms/updateform.phtml')),
));
$this->view->form = $updateForm;

if ($request->isPost()) {
$parameters = $request->getParams();
if(isset($parameters['cancel']))
$this->_redirect('/admin/account/list');
if ($updateForm->isValid($request->getPost())) {
$values = $updateForm->getValues();
$result = Admin_Model_Account::saveData($values);
if($result) $this->_redirect('/admin/account/list');
}
}
As soon as I add the following file field into the form:

public function addImageField($required, $name, $label, $id = NULL) {

$element = new Zend_Form_Element_File($name);
$element->setLabel($label);
$element->setDestination('/var/www/web1/web/public/images/upload');
$element->setDecorators(array(
'Errors',
'File',
array(array('data' => 'HtmlTag'), array('tag' => 'td',
'class' => 'fileInput element', 'id' => $name)),
array('Label', array('tag' => 'td', 'class' =>
'formlabel')),
));
$this->addElement($element);
}


the form never gets passed the

if ($updateForm->isValid($request->getPost()))
in the controller but throws no errors and shows no error messages next to
the form field.

Additional info:
- Of course I played around with different settings and I found that by
removing the setDestination directive in the form element declaration a form
field related error is thrown: File 'logo' exceeds the defined ini size
- Setting the setValueDisabled(true) directive in the element makes no
difference.

Questions:
Why would the form validation fail my form file element - particularly
without throwing any error messages?
How can I get the validation to pass?
--
View this message in context: http://n4.nabble.com/Problem-validating-file-upload-form-field-tp1747289p1747289.html
Sent from the Zend MVC mailing list archive at Nabble.com.

没有评论: