1

I am creating forms like this:

UploadFiale.php

<?php 

class Form_UploadFile extends Zend_Form {

    public function __construct( $options = null ) {

        parent::__construct( $options );    
        $this->setMethod('post');
        $elements = array();

        // photo
        $element = new Zend_Form_Element_File('photo');
        $element->setLabel('Photo');
        $element->addValidator('Count', false, 1);
        $element->addValidator('Size', false, 102400);
        $element->addValidator('Extension', false, 'jpg,png,gif');
        $elements[] = $element;

        // submit button      
        $element = $this->CreateElement('submit', 'submit');
        $element->setLabel('Save');
        $elements[] = $element;

        $this->addElements( $elements );
        $this->setElementDecorators( array( 'ViewHelper' ) );          
        $this->setDecorators( array( array( 'ViewScript', array( 'viewScript' => 'uploadfile-form.phtml' ) ) ) );

    } // end construct       
} // end class
?>

uploadfile-form.phtml

<form action=<?= $this->element->getAction() ?> method=<?= $this->element->getMethod() ?> id='AddNotificationForm' enctype='multipart/form-data' class='AjaxForm'>    
<table border='0'>   
    <tr>
        <td><label><?= $this->element->photo->getLabel() ?></label></td>
        <td><?= $this->element->photo; ?></td>
    </tr>
    <tr>
        <td></td>
        <td><?= $this->element->submit; ?></td>
    </tr>       
</table>    
</form>

When I initialize form class and render it in view then I am getting following error:

Warning: No file decorator found... unable to render file element in /project_folder/library/Zend/Form/Element.php on line 2041

Same structure is working with other form elements but not working with file element. Can someone tell me that what is wrong here ?

Thanks

Student
  • 1,863
  • 9
  • 37
  • 50
  • I tried this `$element->setDecorators(array( array('File'), array('Errors') ));` with file element but still getting same warning. source: http://framework.zend.com/wiki/display/ZFFAQ/Forms – Student Oct 08 '11 at 14:57
  • It looks like this type of error: http://forums.zend.com/viewtopic.php?f=69&t=1701 – Student Oct 08 '11 at 14:58
  • In that case your answer could be this one http://stackoverflow.com/questions/2143462/how-do-i-use-viewscripts-on-zend-form-file-elements – vascowhite Oct 08 '11 at 21:48

1 Answers1

2

Zend_Form_Element_File is special in a way that it does not work without "File" Decorator either you add it specifically or remove

$this->setElementDecorators( array( 'ViewHelper' ) );
Mr Coder
  • 8,169
  • 5
  • 45
  • 74