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
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');
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>
.
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) );
I use this
$element->removeDecorator('DtDdWrapper');
to get rid of the dt dd tags around specific elements
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" />
...