jjmu15
jjmu15

Reputation: 98

Zend_Form_Element_File (no decorator found error)

I am creating a form with an upload element. I have created the file element with the code below

 $image = new Zend_Form_Element_File('image');
 $image->setAttrib('title','Listing Image:')
       ->addDecorator('File')
       ->addValidator('Size', false, 204800)
       ->addValidator('Extension', false, 'jpg,png,gif');

  $this->addElement($image);

Which as far as I can tell works fine. It tries to add a file element to the page. I get an error which says " Warning: No file decorator found... unable to render file element in..."

As you can see I have set the decorator for the element to be the File decorator so I am unsure why I am getting this error?

It is worth noting I have removed all default decorators except for viewHelper and PrepareElements and I am using a view partial as the viewHelper to display the output. Just incase this is required I have also included that below.

<form method="<?php echo $this->element->getMethod(); ?>" action="<?php echo $this->element->getAction(); ?>">
<div class="boxmiddle-Holder">
    <div class="boxmiddle-content">
        <table border="0" cellspacing="2" cellpadding="3" class="dataTable">
            <?php foreach($this->element->getElements() as $element): ?>

                        <!-- if not a button then display label -->
                        <tr>
                            <td><label for="<?php echo $element->getName(); ?>"><?php echo $element->getAttrib('title'); ?></label></td>

                        <td class="normal"><?php echo $element; ?></td>
                        <?php if($element->getMessages()) {
                            foreach($element->getMessages() as $message) { ?>
                                <td> <?php echo "<p class='elementError'>".$message."</p>"; ?></td>
                         <?php    }
                        }
                        ?>
                        </tr>
            <?php endforeach; ?>
       </table>
    </div>
</div>

Any ideas?

Upvotes: 0

Views: 1029

Answers (1)

drew010
drew010

Reputation: 69937

I'd double check to make sure the File decorator isn't being cleared or reset later, that error indicates that your form's file element does not have a Zend_Form_Decorator_File decorator attached to it.

Look in Zend/Form/Element/File.php around line 859 for the function that throws this error. I suspect somehow the File decorator is being removed from the element. It could be that it has no decorators or is just lacking the File decorator.

Hope that helps.

Upvotes: 1

Related Questions