DEVHIDE
        • Home (current)
        • About
        • Contact
        • Cookie
        • Home (current)
        • About
        • Contact
        • Cookie
        • Disclaimer
        • Privacy
        • TOS
        Login Or Sign up

        How can I use zend form decorator to render errors inside my paragraph tag wrapping label and input

        1.8k Views Asked by Fino At 31 October 2011 at 22:09 2025-11-29T13:47:44.500000

        I would like to render the following markup:

        <div class="row">
        <p>
          <label>Your Name</label>
          <input type="text" class="text_field" name="name">
          <ul class="errors">
            <li>Waarde is vereist en kan niet leeg worden gelaten</li>
          </ul>  
        </p>
        </div>
        

        This is my Zend form element + decorator:

        $this->addElement('text', 'name', array(        
                    'label' => 'Naam:',
                    'class' => 'text_field',
                    'required' => true,
                    'decorators' => array(
                        'ViewHelper',
                        'Label',
                        'Errors',
                        array(array('row' => 'HtmlTag'), array('tag' => 'p')),
                        array(array('content' => 'HtmlTag'), array('tag' => 'div', 'class' => 'row'))
                    )));
        

        But this always renders the ul list below the p tag and never inside. It also adds an additional p tag below the list.

        <div class="row">
          <p>
            <label class="required" for="name">Naam:</label>
            <input type="text" class="text_field" value="" id="name" name="name">
          </p>
          <ul class="errors">
            <li>Waarde is vereist en kan niet leeg worden gelaten</li>
          </ul>
          <p></p>
        </div>
        

        What am I doing wrong?

        zend-framework zend-form zend-decorators
        Original Q&A
        2

        There are 2 best solutions below

        0
        Fino Fino On 01 November 2011 at 21:03 BEST ANSWER

        Found it! My stupid mistake. I did only check the final rendered output in my browser. I am using a template which also loads javascript and this changes the DOM which creates the unwanted result.

        So the first decorator setup was working correct.

        1
        Fatalist Fatalist On 01 November 2011 at 15:20

        Try to do the following:

        $this->addElement('text', 'name', array(        
                    'label' => 'Naam:',
                    'class' => 'text_field',
                    'required' => true,
                    'decorators' => array(
                        'ViewHelper',
                        'Label',
                        'Errors',
                        array(array('content' => 'HtmlTag'), array('tag' => 'p')),
                        array(array('content' => 'HtmlTag'), array('tag' => 'div', 'class' => 'row'))
                    )));
        

        Related Questions in ZEND-FRAMEWORK

        • Fatal error: Uncaught exception 'Zend_Acl_Role_Registry_Exception' with message 'Role 'admin' not found
        • Uninstalling php 5.3 in ubuntu 14.04
        • zend soap server reading xml attributes
        • Failed installation of zend-escaper with Composer
        • Composer cannot find Git windows 8
        • Can/How does one make Zend's default (or any other autoloader on the stack) ignore a class?
        • Zend Framework Active Directory authentication
        • Zend: 500 error instead of 404
        • How to force Zend_Navigation_Page_Mvc to generate an href
        • Fatal error: Allowed memory size of 134217728 bytes exhausted (tried to allocate 3 bytes) in E:\library\Zend\Db\Adapter\Pdo\Abstract.php on line 144
        • Zend Gdata - missing HeaderValue.php
        • Cookies on Zend Framework 2
        • Fatal error: Class 'Zend_Pdf_Color_RGB' not found app/code/core/Mage/Sales/Model/Order/Pdf/Shipment.php magento using zend library
        • CORS - request made after preflight request expects 'Access-Control-Allow-Credentials' to be true
        • Why is this form invalid all the time

        Related Questions in ZEND-FORM

        • ZF2 form with fieldset and doctrine not working
        • zf2 form collection hydration gets wrong $data in hydrator
        • Zend 1 to Zend 2, was using decorators, how can i achieve the same behavior now?
        • Zend Form: Call to a member function setValue() on a non-object
        • Zend Form can't validate float number
        • Adding custom attributes in Zend Framework 2 using the Zend Form
        • How to get new uploaded file name in controller?
        • How can I process an unlimited amount of elements using Zend Form
        • Zend routing issue on legacy code
        • How can I replace the File decorator?
        • How to always show single validation message in ZF2 validators?
        • How to pass options to collection fieldset in form created by form manager?
        • Checkbox in Zend Form
        • Zend Form old password verification
        • Unable to delete a record through Zend_Db_Table_Abstract->delete()

        Related Questions in ZEND-DECORATORS

        • How do I allow html tags in label for Zend form element using addElement()?
        • Zend_Form_decorator custom class to input
        • How to change the tag of the default Errors decorator within Zend_Form?
        • overwrite specific Decorators for all Zend_Form Objects
        • Custom Decorator Label in Zend Framework 2
        • Zend_Form: addElementPrefixPath vs addPrefixPath
        • $_disableLoadDefaultDecorators and ZendX_JQuery
        • Decorators in Zend Framework form
        • Zend_Form with CSS
        • Zend_Forms and decorators in ZF - Displaying label, input and errors in one container
        • How can I use zend form decorator to render errors inside my paragraph tag wrapping label and input
        • porting template to zend framework
        • How to change the layout of a form with Zend_Form decorators?
        • Zend Form, table decorators
        • Zend Form ViewScript how to show error messages

        Trending Questions

        • UIImageView Frame Doesn't Reflect Constraints
        • Is it possible to use adb commands to click on a view by finding its ID?
        • How to create a new web character symbol recognizable by html/javascript?
        • Why isn't my CSS3 animation smooth in Google Chrome (but very smooth on other browsers)?
        • Heap Gives Page Fault
        • Connect ffmpeg to Visual Studio 2008
        • Both Object- and ValueAnimator jumps when Duration is set above API LvL 24
        • How to avoid default initialization of objects in std::vector?
        • second argument of the command line arguments in a format other than char** argv or char* argv[]
        • How to improve efficiency of algorithm which generates next lexicographic permutation?
        • Navigating to the another actvity app getting crash in android
        • How to read the particular message format in android and store in sqlite database?
        • Resetting inventory status after order is cancelled
        • Efficiently compute powers of X in SSE/AVX
        • Insert into an external database using ajax and php : POST 500 (Internal Server Error)

        Popular # Hahtags

        javascript python java c# php android html jquery c++ css ios sql mysql r reactjs

        Popular Questions

        • How do I undo the most recent local commits in Git?
        • How can I remove a specific item from an array in JavaScript?
        • How do I delete a Git branch locally and remotely?
        • Find all files containing a specific text (string) on Linux?
        • How do I revert a Git repository to a previous commit?
        • How do I create an HTML button that acts like a link?
        • How do I check out a remote Git branch?
        • How do I force "git pull" to overwrite local files?
        • How do I list all files of a directory?
        • How to check whether a string contains a substring in JavaScript?
        • How do I redirect to another webpage?
        • How can I iterate over rows in a Pandas DataFrame?
        • How do I convert a String to an int in Java?
        • Does Python have a string 'contains' substring method?
        • How do I check if a string contains a specific word?
        .

        Copyright © 2021 Jogjafile Inc.

        • Disclaimer
        • Privacy
        • TOS
        • Homegardensmart
        • Math
        • Aftereffectstemplates