1

Hi I have problem with File element on my custom zend_form. Thats the code:

class Core_Form extends Zend_Form
{


protected $_containerId;
public function  __construct($options = null) {
    parent::__construct($options);

    $this->setElementDecorators(array(
        'ViewHelper',
        array(
            'Description',
            array(
                'tag'    => 'div',
                'class'  => 'submit-button',
                'escape' => false
            )
        ),
        array(
            array(
                'data' => 'HtmlTag'
            ),
            array(
                'tag'   => 'div',
                'class' => 'element'
            )
        ),
        array(
            'Label',
            array(
                'tag'    => 'div',
                'escape' => false
            )
        ),
        array(
            array(
                'row' => 'HtmlTag'
            ),
            array(
                'tag'   => 'div',
                'class' => 'element-row'
            ),
        ),
        'Errors'
    ));

    $this->setDecorators(array(
        'FormElements',
        array(
            'HtmlTag',
            array(
                'tag' => 'div',
                'id'  => $this->_containerId
            )
        ),
        'Form',
        'Errors'
    ));
}
}
 //upload form
 class Upload_Form extends Core_Form
 {

public function init()
{
    /* Form Elements & Other Definitions Here ... */

    $this->addElement('file', 'uploadFile', array(
        'destination' => APPLICATION_PATH.'/../public/uploads/ads',
        'validators' => array(
            array('count', false, 1),
            array('size', false, 102400),
        ),
        'label' => 'Wyślij plik:'
    ));

    $this->addElement('image', 'submit', array(
        'label' => false,
        'ignore' => true,
        'src'    => $this->getView()->baseUrl('images/send.jpg')
    ));

    $this->setEnctype('multipart/form-data');
}

}

i getting this error: Warning: Exception caught by form: No file decorator found... unable to render file element

when I change my ViewHelper in element decorators to 'File' i getting this error: Warning: Exception caught by form: Method getMaxFileSize does not exist Stack Trace: #0 [internal function]: Zend_Form_Element->__call('getMaxFileSize', Array)

Thank you in advance for your help

JokerDark2
  • 97
  • 2
  • 7

1 Answers1

2

You'll need to set a different set of decorators for the File element, it needs to use the 'File' decorator.

You can see a very similar question here: How do I use ViewScripts on Zend_Form File Elements?

Hope that helps,

Community
  • 1
  • 1
dinopmi
  • 2,683
  • 19
  • 24
  • Hi thanks for answer! Yes it gives me possibility to make it work but its not exactly how i want to solve this problem... i wanna to set my decorators in Core_Form definition... with this solution i have to get every time 'upload' element and setdecorators... is there any way to setup my decorators in base core form definition to make it work every time like its in original Zend_Form? – JokerDark2 Oct 20 '11 at 21:40
  • You could just loop through all the elements of the form after you have added them, and select a kind of decorator depending on the element type. It's not an unelegant solution. – dinopmi Oct 24 '11 at 11:05