Zend Framework: How do I remove the decorators on a Zend Form Hidden Element?

后端 未结 11 1646
说谎
说谎 2020-12-23 00:07

I\'m trying to remove the default decorators on a hidden form element. By default, the hidden element is displayed like this:

Hidden Element Label
相关标签:
11条回答
  • 2020-12-23 00:19

    When you have a lot of hidden inputs best answer is the following:

    $elements = $this->getElements();
    foreach ($elements as $elem)
        if ($elem instanceof Zend_Form_Element_Hidden)
            $elem->removeDecorator('label')->removeDecorator('HtmlTag');
    
    0 讨论(0)
  • 2020-12-23 00:19

    Using only a single "ViewHelper" decorator will generate invalid markup if you're still using the <dl> wrapper. Another approach is outlined in ZF-2718. This adds hidden fields to a subform that is wrapped in a <dd>.

    0 讨论(0)
  • 2020-12-23 00:20

    From the Zend Element Decorators documentation:

    Default Decorators Do Not Need to Be Loaded

    By default, the default decorators are loaded during object initialization. You can disable this by passing the 'disableLoadDefaultDecorators' option to the constructor:

    $element = new Zend_Form_Element('foo', 
        array('disableLoadDefaultDecorators' => true)
    );
    
    0 讨论(0)
  • 2020-12-23 00:31

    I use this

    $element->removeDecorator('DtDdWrapper');
    

    to get rid of the dt dd tags around specific elements

    0 讨论(0)
  • 2020-12-23 00:34

    I couldn't get disableLoadDefaultDecorators to work quite right. Here's a solution I came up with.

    $hiddenIdField = new Zend_Form_Element_Hidden('id');
    $hiddenIdField->setValue($portalId)
                  ->removeDecorator('label')
                  ->removeDecorator('HtmlTag'); 
    

    In the HTML, the hidden field appears without any extra tags around it.

    ...
    <dt><label for="password" class="required">Password</label></dt>
    <dd><input type="password" name="password" id="password" value="" /></dd>
    <input type="hidden" name="id" value="1" id="id" />
    ...
    
    0 讨论(0)
提交回复
热议问题