ZF-6796: Zend_Form_Element_File - unable to create a Custom ErrorMessage

Issue Type: Bug Created: 2009-05-25T06:57:25.000+0000 Last Updated: 2009-05-26T06:47:59.000+0000 Status: Resolved Fix version(s): - 1.8.0 (30/Apr/09)

Reporter: Gerrit B (virus-2k) Assignee: Thomas Weidner (thomas) Tags: - Zend_Form

Related issues: Attachments:


I think a Code explains it very well. I want to Add Custom Error Messages in a Zend_Form_Element_File-Field. In a Zend_Form_Element_Text this is no Problem and works well with $form->txtelementname->addError( 'custom message' )

But it doesn't work with Zend_Form_Element_File. Here's a example code (copied from my controller)

I needed this because i want to check the filemime with my function. (Please ask not why because i think that's irrelevant)

<pre class="highlight"> 

// inner action function

require_once( FORM_PATH . 'AdminDownloadUpload.php' );
$form = new Frm_AdminDownloadUpload();

if( $this->getRequest()->isPost() ) {
            $fileValid = false;
            if( $form->file->isValid( $this->getRequest()->getPost() ) ) {
               if( !$form->file->receive() ) {
                    $form->file->addError( '' );

                if( !$form->isErrors() && $form->file->isUploaded() && $form->file->isReceived() ) {
                    // check for valid mime
                    $check = Frames::getInstance()->checkMime( null, $form->file->getFileName() );
                    if( !$check ) {
                        $form->file->addError( '' );
                        @unlink( $form->file->getFileName() );
                    } else {
                        $fileValid = true;
            if( $form->isValid( $this->getRequest()->getPost() ) ) {
                $post = $form->getValues();
                // works?!              
                var_dump( $post );
            } else {
                // delete file again because form isn't valid
                if( $fileValid ) {
                    $form->file->addError( '' );
                    if( file_exists( $form->file->getFileName() ) ) @unlink( $form->file->getFileName() );

        $this->view->assign( 'form', $form );



Posted by Thomas Weidner (thomas) on 2009-05-25T14:07:56.000+0000

Are you sure you're on ZF 1.8 ? The actual unittests for this component cover also addError and show no problem. User-errors are also returned.

What your code does not explain is what you get returned as failure because I don't see that you are calling getErrors().

Posted by Gerrit B (virus-2k) on 2009-05-25T15:12:10.000+0000

I use the Zend MVC. So i only do a in the Template. I don't use getErrors because Zend_Form does the Job for me?! (as you see in the Controller $form->isValid..)

On all other Fields I got a ErrorMessage (incl. CustomErrorMessages) right under the input-Field except for the File Element.

Posted by Thomas Weidner (thomas) on 2009-05-26T03:13:58.000+0000

render(new Zend\_View());?>

Posted by Gerrit B (virus-2k) on 2009-05-26T05:40:32.000+0000

Ok, ok. It's all my fault.

I checked the Versions now and found out, that the Script uses the ZF installed on Server (which was 1.7.5) and not the ZF in my Library Path. It works as expected with Version 1.8.1 and I'm sorry for my mistake. :-/

Thanks anyway.

Posted by Gerrit B (virus-2k) on 2009-05-26T05:41:51.000+0000

I've updated this issue to Version 1.7.5 not 1.8.1.

Posted by Thomas Weidner (thomas) on 2009-05-26T06:47:56.000+0000

Closing as duplicate

Have you found an issue?

See the Overview section for more details.


© 2006-2018 by Zend, a Rogue Wave Company. Made with by awesome contributors.

This website is built using zend-expressive and it runs on PHP 7.