ZF-6867: Zend_Form_Element_File setDecorators issue


Hi, I had the needs to remove all decorators for a Zend_Form_Element_File element and then add a 'div' container to it. But I get this warning:

Warning: Exception caught by form: No file decorator found... unable to render file element Stack Trace: #0 C:\wamp\myproject\library\Zend\Form\Decorator\FormElements.php(101): Zend_Form_Element_File->render() #1 C:\wamp\myproject\library\Zend\Form.php(2595): Zend_Form_Decorator_FormElements->render('') #2 C:\wamp\myproject\library\Zend\Form.php(2610): Zend_Form->render() #3 C:\wamp\myproject\application\modules\admin\views\scripts\media\edit.phtml(6): Zend_Form->__toString() #4 C:\wamp\myproject\library\Zend\View.php(107): include('C:\wamp\myproje...') #5 C:\wamp\myproject\library\Zend\View\Abstract.php(832): Zend_View->_run('C:\wamp\myproje...') #6 C:\wamp\myproject\library\Zend\Controller\Action\Helper\ViewRenderer.php(902): Zend_View_Abstract->render('media/edit.phtm...') #7 C:\wamp\myproject\library\Zend\Controller\Action\Helper\ViewRenderer.php(923): Zend_Controller_Action_Helper_ViewRenderer->renderScript('media/edit.phtm...', NULL) #8 C:\wamp\myproject\library\Zend\Controller\Action\Helper\Vi in C:\wamp\myproject\library\Zend\Form.php on line 2615

this is the code for the file element, the above warning is caused by the setDecorators method

  $mediafile = new Zend_Form_Element_File('mediafile');

Zend Framework version 1.8.1 and 1.8.2. I used the workaround explained here:…

to make it work as I need.


Please note that this is not a bug.

Several elements like File, Image or Captcha need own decorators, otherwise they could not be rendered. As you deleted all default decorators and gave not the needed file decorator to the file element, the file element itself throws an exception as it can not be rendered properly.

This has been mentioned in FAQ. ( ) Also several issues have been filled and answered in past.

Seems to me that the file element should check to see if the decorator is using ViewHelper and give a more descriptive error message. At least this way, people could get on the right track.

In my opinion "File decorator not found/set" is a proper error message. You could have a file element with File and ViewHelper decorator set.

The exception was added because many people did simply not read the manual. In past there was no error at all, the file element did simply not work.

Anyway: It is mentioned within the manual at 2 places, within the FAQ, within the mailing list and also within several public places which can be found on the web.

Even when the text would be changed to "Stupid: you must add the file decorator" there are still many people which will raise an issue instead of reading or searching first. ;-)