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

后端 未结 11 1643
说谎
说谎 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:15

    Well, 2012 and still the same issue. If you remove the decorators, the html won't validate. If you leave them, the hidden elements take up space. In all of my projects I have a CSS helper .hidden, so I just apply it to the

    and unset the label:

    $element = new Zend_Form_Element_Hidden('foo', array('value' => 'bar'));
    $element->removeDecorator('Label');
    $element->getDecorator('HtmlTag')->setOption('class', 'hidden');
    

    Valid html(5), nice looking forms. This can also go into a custom decorator for the hidden fields.

    EDIT

    This is how I put it into my own form element:

    class Exanto_Form_Element_Hidden extends Zend_Form_Element_Hidden
    {
        public function render(Zend_View_Interface $view = null)
        {
            $this->removeDecorator('Label');
            $this->getDecorator('HtmlTag')->setOption('class', 'hidden');
            return parent::render($view);
        }
    }
    

提交回复
热议问题