Well, when you want to display a own error message, then you have to set the correct message constant.

NOT_FOUND is, as it's text says, for "file not found"...
FALSE_EXTENSION is as it's text says for "file has the false extension...

So why should your text be displayed when you set the false constant ?
Giving "NOT_FOUND" will not be displayed when the extension is false.

I would simply set the correct message constant to get the wished output.
Running your code I get eighter
"[fileUploadErrorNoFile] => The file 'file' was not uploaded " when no file was uploaded, or "[fileUploadErrorNoFile] => The file 'file' was not uploaded " when a false extension was used.

And when I change your code from NOT_FOUND to FALSE_EXTENSION then I get
"[fileExtensionFalse] => not a gif image " displayed when I do print_r on getMessages() from the form.

Greetings
Thomas Weidner, I18N Team Leader, Zend Framework
http://www.thomasweidner.com

----- Original Message ----- From: "Jacky Chen" <[email protected]>
To: "Thomas Weidner" <[email protected]>
Sent: Tuesday, March 31, 2009 4:42 AM
Subject: Re: [fw-general] about zend_form_element_file error messages


OK,i want to validate a form file element if an image with gif extension,but
no error messages be displayed after the form validate failed.
just try this:

<?php
required_once 'Zend/Controller/Action.php';

class IndexController extends Zend_Controller_Action
{
   public function indexAction()
   {
       $form = new Zend_Form();
       $form->setEnctype(Zend_Form::ENCTYPE_MULTIPART);

       $image = new Zend_Form_Element_File('image');
       $image->setLabel('upload a gif image');
       $image->setRequired(true);

$image->addValidator('extension',true,array('gif','messages'=>array(Zend_Validate_File_Extension::NOT_FOUND=>'not
a gif image')));

       $form->addElement($image);
       $form->addElement('submit','submit');

       if ($this->_request->isPost() &&
$form->isValid($this->_request->getPost()) {
           echo 'validate success';
       }

       $this->view->form = $form;
   }
}
?>

views/script/index/index.phtml

<?php
echo $this->form;
?>

run this page,then upload a file that is not gif extension,the form would
validate failed.But the error message of 'not a gif image' not displayed
bellow to the form file element.

Best Regards,
Jacky

2009/3/31 Thomas Weidner <[email protected]>

And why should they be assigned by isValid() ? No one said that.

Instead of thinking that the implementation does not work it would be
better if you say where you have a problem.
It makes no sense to discuss ZF internal code which works and is tested
;-).

Greetings
Thomas Weidner, I18N Team Leader, Zend Framework
http://www.thomasweidner.com

----- Original Message ----- From: "Jacky Chen" <[email protected]>
To: "Thomas Weidner" <[email protected]>
Sent: Monday, March 30, 2009 7:32 PM
Subject: Re: [fw-general] about zend_form_element_file error messages



 but in the isValid() method of the form file element,no error messages
were
assigned to the form by file adapter.
Best Regards,
Jacky

2009/3/30 Thomas Weidner <[email protected]>

 Error messages from the form are not assigned to the file adapter.
It is the other way round... error messages from the file adapter are
assigned to the form.

Greetings
Thomas Weidner, I18N Team Leader, Zend Framework
http://www.thomasweidner.com

----- Original Message ----- From: "Jacky Chen" <[email protected]>
To: <[email protected]>
Sent: Monday, March 30, 2009 12:36 PM
Subject: [fw-general] about zend_form_element_file error messages



 Hi,

is it not implement the error messages process for the form file element just now,or missing that? no error messages are assign to the form file
element after the file adapter validated the file element.

Best Regards,
Jacky








Reply via email to