Reputation:
I have one simple problem, but I was googling it for about 2-3 hours and found nothing. So, this is my Form code snippet:
$element = new Zend_Form_Element_File("photo");
$element->setRequired()
->setDestination(realpath(APPLICATION_PATH . '/../public/uploaded_photos'))
->addValidator('Count', false, 1)
->addValidator('Size', false, 102400)
->addValidator('Extension', false, 'jpg,png,gif') -> addValidator(new Zend_Validate_NotEmpty())
->setAllowEmpty(false);
$this->addElement($element);
$this->setDecorators(array(
array('ViewScript', array('viewScript' => 'forms/_form_addFile.phtml'))));
$this->setElementDecorators(array('ViewHelper'));
But in place of file input I have this warning:
Warning: No file decorator found... unable to render file element in /home/wroblewski/ZendFramework-1.12.3/library/Zend/Form/Element.php on line 2060
Somemody maybe knows how to fix it? I have no idea what should I do now, because I've never used File input. Please help :)
Upvotes: 1
Views: 259
Reputation: 4635
Can you try adding the file element after the decorators has been set in the form, ie place $this->addElement($element);
after $this->setElementDecorators(array('ViewHelper'));
.
This is because $this->setElementDecorators
will remove all decorators that have been set in the element by default and will set only the ones you have set it via $this->setElementDecorators()
, in this case only ViewHelper
will be set in the file element. But file element need more decorators to render the element. So adding the element after the decorators been set will prevent it from removing the required ones.
Or You can specify the elements to be excluded in an array format as the second parameter of the function. Check Zend/Form.php
Line 2832.
/**
* Set all element decorators as specified
*
* @param array $decorators
* @param array|null $elements Specific elements to decorate or exclude from decoration
* @param bool $include Whether $elements is an inclusion or exclusion list
* @return Zend_Form
*/
public function setElementDecorators(array $decorators, array $elements = null, $include = true)
{
.
.
Upvotes: 1