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
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);
}
}