1

I have trouble using decorators in combination with $logo=$this->createElement('file', 'logo')

I have a form in table style, everything worked quite fine until I wanted to add a file element. Here is the related part of my code (form class):

 $logo=$this->createElement('file', 'logo')
        ->setLabel('logo:')
        ->setDestination(APPLICATION_PATH . "/../public/images/logos")
        ->addValidator('Count', false, 1)                           
        ->addValidator('Size', false, 1024000)                      
        ->addValidator('Extension', false, 'jpg,png,gif,jpeg');     

    $logo->setDecorators(array(
          'ViewHelper',
           'Description',
           'Errors', array(array('data'=>'HtmlTag'), array('tag' => 'td',
           'colspan'=>'2','align'=>'center')),
           array(array('row'=>'HtmlTag'),array('tag'=>'tr'))    //, 'closeOnly'=>'true'
   ));

I got an error message as following: Warning: Exception caught by form: No file decorator found... unable to render file element Stack Trace

Which could be the solution?

pia-sophie
  • 505
  • 4
  • 21
  • possible duplicate of [Zend File Upload and Element Decorators](http://stackoverflow.com/questions/7580839/zend-file-upload-and-element-decorators) – Richard Parnaby-King May 05 '15 at 10:48

1 Answers1

1

The File element requires it's own decorator - Zend_Form_Decorator_File.

Change ViewHelper for File:

$logo->setDecorators(
    array(
        'File',
        'Description',
        'Errors', array(array('data'=>'HtmlTag'), array('tag' => 'td',
        'colspan'=>'2','align'=>'center')),
        array(array('row'=>'HtmlTag'),array('tag'=>'tr'))    //, 'closeOnly'=>'true'
    )
);
Richard Parnaby-King
  • 14,703
  • 11
  • 69
  • 129