Issues

ZF-5878: Zend_Form_Element_File does not register errors nor display them

Issue Type: Improvement Created: 2009-02-24T11:04:36.000+0000 Last Updated: 2009-03-05T23:02:34.000+0000 Status: Resolved Fix version(s): - 1.8.0 (30/Apr/09)

Reporter: Remy Damour (remy215) Assignee: Thomas Weidner (thomas) Tags: - Zend_Form

Related issues: Attachments:

Description

When I add an error to a Zend_Form_Element_File element: - -error is not registered- error is registered, it is not returned by ::getErrors() but returned by ::getErrorMessages() - error is not outputed when element is rendered whereas same piece of code on non-file element (text / textarea / checkbox ...) works perfectly.

Example:

<pre class="highlight">
<?php
// note: $form points to a Zend_Form instance and 'attachment' is a Zend_Form_Element_File object
$form->attachment->addError('An error occured');
...
echo $form->attachment; 
?>

Actual result:

<pre class="highlight">
Attach file

Expected result:

<pre class="highlight">
Attach file


An error occured

Comments

Posted by Remy Damour (remy215) on 2009-02-24T11:27:05.000+0000


 

 

Posted by Thomas Weidner (thomas) on 2009-02-24T23:26:58.000+0000

Please give a complete example of your element and form creation/validation. Because errors are rendered and tested in the testbed and displayed in my browser.

 

 

Posted by Remy Damour (remy215) on 2009-02-25T00:52:07.000+0000

I've created a very simple controller action that does only one thing, output a form with an error attached on File element.

Here is /application/controllers/IndexController.php:

 
    <pre class="highlight">
    <?php
    require_once 'Zend/Controller/Action.php';
    
    /**
     * Default controller, used for redirections only
     */
    class IndexController extends Zend_Controller_Action
    {
        /**
         * Show upload form
         */
        public function indexAction()
        {
            require_once 'Zend/Form.php';
            $form = new Zend_Form();
            $form->setAction('/file/upload')
                     ->setMethod('post');
            $attachment = $form->createElement('file', 'attachment')->setLabel('Upload a file')->addError('An error occured');
            $form->addElement($attachment);
            $this->view->form = $form;
        }
    }


Here is /application/views/scripts/index/index.phtml:

 
    <pre class="highlight">
    <?php echo $this->form->render(); 

Actual Result:

 
    <pre class="highlight">


    Upload a file
    

 

 

Posted by Thomas Weidner (thomas) on 2009-02-25T02:02:49.000+0000

I see... To describe this:

The file element is based on the file transfer adapter. So also the error is thrown from the adapter.

When you create a new error type with addError, this is not supported by files because the adapter would not know where he should attach it. Files themself do not have a error, they are working with validators.

Also, when you add a new errortype where should it be attached ...at the first validator ? What when you delete this validator ? ...at all validators ? Same error would be displayed multiple times ? ...and when this works, only displaying the attached error ? Or also the file errors ?

I would solve this different, at the time you validate / receive the file as shown in several examples.

Btw: renderErrors() works by me, but displays as described previously only file errors.

 

 

Posted by Thomas Weidner (thomas) on 2009-02-25T03:39:07.000+0000

Changed type from bug to improvement. Will be reviewed internally.

 

 

Posted by Remy Damour (remy215) on 2009-02-25T05:25:41.000+0000

If addError method is not used, it may be interesting for it to throw an exception. Thanks for the explanation anyway.

 

 

Posted by Thomas Weidner (thomas) on 2009-03-05T23:02:34.000+0000

Integrated with r14233

 

 

Have you found an issue?

See the Overview section for more details.

Copyright

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

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

Contacts