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

Andrew picture Andrew · Jan 27, 2009 · Viewed 54.4k times · Source

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

<dt>Hidden Element Label (if I had set one)</dt>
<dd><input type="hidden" name="foobar" value="1" id="foobar"></dd>

I don't want my hidden element to take up space on my page. I want to remove all the default decorators so all I'm left with is the input tag.

<input type="hidden" name="foobar" value="1" id="foobar">

How can I achieve this?

Answer

ischenkodv picture ischenkodv · Dec 7, 2010

For hidden field you need only one decorator - ViewHelper:

$field = new Zend_Form_Element_Hidden('id');
$field->setDecorators(array('ViewHelper'));

This will render only the input field, without Dt-Dd wrapper and label.