Download Zend Files and Element Decorators

I have a problem that the next Zend Form is causing an error. The problem is with the "file" element and using setElementDecorators.

class Products_AddForm extends Zend_Form { function init() { // other form elements... $uploadElement = new Zend_Form_Element_File('Excel'); $uploadElement->setLabel('Excel'); $this->addElement($uploadElement); $this->setElementDecorators(array( 'ViewHelper', 'Errors', array(array('data' => 'HtmlTag'), array('tag' => 'td')), array('Label', array('tag' => 'th')), array(array('row' => 'HtmlTag'), array('tag' => 'tr')) )); } } 

This causes an error.

 (Warning: Exception caught by form: No file decorator found... unable to render file element Stack Trace: #0 ) 

Adding $uploadElement->addDecorator('File'); at the end after SetElementDecorators will work, but it will give me the file element twice!

Can someone help please?

TIA Matt

+6
source share
1 answer

The File element requires its own decorator, Zend_Form_Decorator_File.

 $this->setElementDecorators(array( 'File', 'Errors', array(array('data' => 'HtmlTag'), array('tag' => 'td')), array('Label', array('tag' => 'th')), array(array('row' => 'HtmlTag'), array('tag' => 'tr')) )); 

[edit]

Just noticed that you are also using other form elements.

After your source code, add:

 $this->getElement('Excel')->setDecorators( array( 'File', 'Errors', array(array('data' => 'HtmlTag'), array('tag' => 'td')), array('Label', array('tag' => 'th')), array(array('row' => 'HtmlTag'), array('tag' => 'tr')) ) ); 

Thus, the ViewHelper is added to all other elements, and the File file is used instead.

+10
source

Source: https://habr.com/ru/post/898195/


All Articles