0

I created a custom viewscript for a zend form. In the form, there is a file element. When I run the code echo $this->element->elementname->renderViewHelper() it works fine on all elements except the file element. When I run the following code on my file element within my custom viewscript, i get the following error: Uncaught exception 'Zend_Form_Element_Exception' with message 'Decorator by name ViewHelper does not exist'

<?php if($this->element->avatarimage->hasErrors()):?>
        <div class="control-group error">
    <?php else: ?>
        <div class="control-group">
    <?php endif;?>
        <label for="avatarimage" class="control-label">Avatar Image</label>
        <div class="controls">
            <?php echo $this->element->avatarimage->renderViewHelper();?>
            <?php if($this->element->avatarimage->hasErrors()):
                    $messages = $this->element->avatarimage->getMessages();
                    $messages = array_values($messages);
                    $message  = $messages[0];
                    echo '<span class="help-inline">'.$message.'</span>';
                endif;
            ?>              
        </div>
    </div>

How can I incorporate my file element into my custom form viewscript?

2 Answers 2

3

This should definitely work.

<? echo $this->element->avatarimage->renderFile(); ?>
Sign up to request clarification or add additional context in comments.

1 Comment

God Bless you wherever you are. That saved so much of my time.
0

Try like this:

<?php echo $this->element->avatarimage;?>

6 Comments

This semi solves my problem. When I do this, I get the extra html content attached to the avatarimage element (the dt's and dd's). With every other element, calling renderViewHelper returns just the input html.
You need to remove the the decorator from the element at the form class. For example $element->removeDecorator('DtDdWrapper');
BTW you can also remove other decorators : $element->removeDecorator('label') $element->removeDecorator('htmlTag'); You can read a more about decorators here framework.zend.com/manual/en/zend.form.standardDecorators.html
i tried removing the decorators from the avatarimage element and used your code. still not working.
But what do you mean with "still not working"? do you still see the additional html generated?
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.