You must have deleted one line because you did not set setRequired(false) in
your code.
This means that the file element must be given as it's required.
And this means that the file will ALWAYS be validated and returns a failure
message when no file is given.
Add setRequired(false) to your code to set the file element to be optional.
Greetings
Thomas Weidner, I18N Team Leader, Zend Framework
http://www.thomasweidner.com
----- Original Message -----
From: "Michel Morelli" <mic...@ziobuddalabs.it>
To: <fw-general@lists.zend.com>
Sent: Monday, January 19, 2009 7:16 PM
Subject: [fw-general] Zend_Form and File upload
Hi all. I have this file upload element and it is a NOT required element
(setRequired(false)):
$mainpic = $this->createElement('file','mainpic');
$mainpic->setLabel('Immagine di riferimento:')
->setDestination('/tmp');
// ensure only 1 file
//$mainpic->addValidator('Count', false, 1);
// limit to 100K
$mainpic->addValidator('Size', false, 102400);
// only JPEG, PNG, and GIFs
$mainpic->addValidator('Extension', false, 'jpg,png,gif');
$mainpic->setDecorators($decorators)
->addDecorator('HtmlTag',array('tag' => 'div', 'class'
=> 'field_mainpic'))
->addDecorator('Description', array('escape' => false,
'tag' => 'span', 'class' => 'description'));
My problem is that when I click the submit button my form is not valid
and the error is in the file element, and these are the error messages :
* The file '' could not be found
* The file '' was not found
Where is my error ? The problem are the 'Count' and 'Extension'
validator, but why they run if the file is not required ?
M.
--
Michel 'ZioBudda' Morelli mic...@ziobuddalabs.it
Consulenza sistemistica in ambito OpenSource.
Sviluppo applicazioni web dinamiche (LAMP+Ajax)
Telefono: 0200619074
Telefono Cell: +39-3939890025 -- Fax: +39-0291390660
http://www.ziobudda.net ICQ: 58351764
http://www.ziobuddalabs.it Skype: zio_budda
http://www.ajaxblog.it MSN: mic...@ziobuddalabs.it
JABBER: mic...@gmail.com