Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6666085
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T02:47:29+00:00 2026-05-26T02:47:29+00:00

I know I can remove the extra stuff from each element individually like so

  • 0

I know I can remove the extra stuff from each element individually like so

$button ->removeDecorator('DtDdWrapper')
        ->removeDecorator('HtmlTag')
     ->removeDecorator('Label');

I was wondering if I can achieve the same for all my elements in a zend form?
And how does one remove the dl wrapping the form?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T02:47:30+00:00Added an answer on May 26, 2026 at 2:47 am

    Markus, here is a solution that I use that seems to work well, hopefully it will be suitable for you.

    First, in order to render the form with no <dl> tag, we need to set the decorators on form object itself. From inside a class extending Zend_Form, you would call Zend_Form->setDecorators() passing an array of form decorators.

    From the reference guide:

    The default decorators for Zend_Form are FormElements, HtmlTag (wraps in a definition list), and Form; the equivalent code for creating them is as follows:

      $form->setDecorators(array(
          'FormElements',
          array('HtmlTag', array('tag' => 'dl')),
          'Form'
      ));
    

    To wrap the form in something other than a dl, we use the above decorators but change the dl to whatever tag you use, I typically use a div of class form which we will see later.

    Next, the elements need to be dealt with. Zend_Form elements have different decorators for different types of elements. The following groups of element types each have their own distinct set of decorators: [Submit & Button], [Captcha], [File], [Image], and [Radio*]. The decorator for radio is very similar to standard elements except that it does not specify the for attribute inside the label.

    All other form elements, text, password, select, checkbox, etc use the same set of default decorators.

    To remove the dd/dt tags from an individual form element we would need to apply our own set of decorators to it. Here is an example that does not use dd/dt tags:

    array(
        'ViewHelper',
        'Errors',
        array('Description', array('tag' => 'p', 'class' => 'description')),
        array('HtmlTag',     array('class' => 'form-div')),
        array('Label',       array('class' => 'form-label'))
    );
    

    This will wrap each form element in a div tag with the class form-div. The problem is, you have to apply this set of decorators to EVERY element that you don’t want to be wrapped in the dd/dt tags which can be a bit problematic.

    To solve this issue, I create a class that extends from Zend_Form and give it some default behavior and decorators that are different from the default decorators for Zend_Form.

    While we can’t quite have Zend_Form automatically assign the correct decorators to specific element types (you can assign them to specific element names), we can set a default, and give ourselves easy access to the decorators from one place, so if they need to change, they can be easily changed for all forms.

    Here is the base class:

    <?php
    
    class Application_Form_Base extends Zend_Form
    {
        /** @var array Decorators to use for standard form elements */
        // these will be applied to our text, password, select, checkbox and radio elements by default
        public $elementDecorators = array(
            'ViewHelper',
            'Errors',
            array('Description', array('tag' => 'p', 'class' => 'description')),
            array('HtmlTag',     array('class' => 'form-div')),
            array('Label',       array('class' => 'form-label', 'requiredSuffix' => '*'))
        );
    
        /** @var array Decorators for File input elements */
        // these will be used for file elements
        public $fileDecorators = array(
            'File',
            'Errors',
            array('Description', array('tag' => 'p', 'class' => 'description')),
            array('HtmlTag',     array('class' => 'form-div')),
            array('Label',       array('class' => 'form-label', 'requiredSuffix' => '*'))
        );
    
        /** @var array Decorator to use for standard for elements except do not wrap in HtmlTag */
        // this array gets set up in the constructor 
        // this can be used if you do not want an element wrapped in a div tag at all
        public $elementDecoratorsNoTag = array();
    
        /** @var array Decorators for button and submit elements */
        // decorators that will be used for submit and button elements
        public $buttonDecorators = array(
            'ViewHelper',
            array('HtmlTag', array('tag' => 'div', 'class' => 'form-button'))
        );
    
    
        public function __construct()
        {
            // first set up the $elementDecoratorsNoTag decorator, this is a copy of our regular element decorators, but do not get wrapped in a div tag
            foreach($this->elementDecorators as $decorator) {
                if (is_array($decorator) && $decorator[0] == 'HtmlTag') {
                    continue; // skip copying this value to the decorator
                }
                $this->elementDecoratorsNoTag[] = $decorator;
            }
    
            // set the decorator for the form itself, this wraps the <form> elements in a div tag instead of a dl tag 
            $this->setDecorators(array(
                                 'FormElements',
                                 array('HtmlTag', array('tag' => 'div', 'class' => 'form')),
                                 'Form'));
    
            // set the default decorators to our element decorators, any elements added to the form
            // will use these decorators
            $this->setElementDecorators($this->elementDecorators);
    
            parent::__construct();
            // parent::__construct must be called last because it calls $form->init()
            // and anything after it is not executed
        }
    }
    
    /*
       Zend_Form_Element default decorators:
       $this->addDecorator('ViewHelper')
            ->addDecorator('Errors')
            ->addDecorator('Description', array('tag' => 'p', 'class' => 'description'))
            ->addDecorator('HtmlTag', array('tag' => 'dd',
                                            'id'  => array('callback' => $getId)))
            ->addDecorator('Label', array('tag' => 'dt'));
    */
    

    Now to use the class, extend all of your forms from this base class and go about assigning elements as usual. If you use Zend_Form_Element_XXX as opposed to addElement() then you will need to pass one of the decorators as an option to the element constructor, if you use Zend_Form->addElement, then it will use the default decorator $elementDecorators we assigned in the class.

    Here is an example that shows how to extend from that class:

    <?php
    
    class Application_Form_Test extends Application_Form_Base
    {
        public function init()
        {
            // Add a text element, this will automatically use Application_Form_Base->elementDecorators for its decorators
            $this->addElement('text', 'username', array(
                'label'      => 'User Name:',
                'required'   => false,
                'filters'    => array('StringTrim'),
            ));
    
            // This will not use the correct decorators unless we specify them directly
            $text2 = new Zend_Form_Element_Text(
                'text2',
                array(
                    'decorators' => $this->elementDecorators, // must give the right decorator
                    'label' => 'Text 2'
                )
            );
    
            $this->addElement($text2);
    
            // add another element, this also uses $elementDecorators
            $this->addElement('text', 'email', array(
                'label'      => 'Email:', 
                'required'   => false,
                'filters'    => array('StringTrim', 'StringToLower'), 
            ));
    
            // add a submit button, we don't want to use $elementDecorators, so pass the button decorators instead
            $this->addElement('submit', 'submit', array(
                'label' => 'Continue', 
                'decorators' => $this->buttonDecorators // specify the button decorators
            ));
        }
    }
    

    This shows a pretty effective way to get rid of the dd/dt and dl elements and replace them with your own. It is a bit inconvenient to have to specify the decorators for every element, as opposed to being able to assign decorators to specific elements, but this seems to work well.

    To add one more solution that I think you were looking to do, if you would like to render an element with no label, simply create a new decorator and omit the label decorator from it like this:

    $elementDecorators = array(
        'ViewHelper',
        'Errors',
        array('Description', array('tag' => 'p', 'class' => 'description')),
        array('HtmlTag',     array('class' => 'form-div')),
        // array('Label',       array('class' => 'form-label', 'requiredSuffix' => '*'))
        // comment out or remove the Label decorator from the element in question
        // you can do the same for any of the decorators if you don't want them rendered
    );
    

    Feel free to ask for clarification on anything, hopefully this will help you out.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

How can I remove focus from submit button? I don't know why it is
Can anybody know how to remove all the indexes from database ?
What is the best way to remove the extra 00-00-00-00-00's from my byte[512]? Currently
How can I remove all extra space between words in a string literal? some
This is something I know can be done somehow , because I've done it
I have a query that I know can be done using a subselect, but
You can know if the event stack is empty calling the gtk.events_pending() method, but
I know I can do most of this by hacking Trac and using Git
I know you can look at the row.count or tables.count, but are there other
I know you can do redirection based on the domain or path to rewrite

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.