Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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?

like image 326
Andrew Avatar asked Jan 26 '09 23:01

Andrew


2 Answers

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.

like image 92
ischenkodv Avatar answered Oct 22 '22 17:10

ischenkodv


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) ); 
like image 26
drfloob Avatar answered Oct 22 '22 17:10

drfloob