This question come a lot in #ZFtalk channel on IRC.
The Default decorator apply the DtDdWrapper to all form element when they are created. But hidden field does’nt need decorator and the actual hidden element class does’nt care about that.
Actually, without decorator remove, hidden field will output like the following and this is bad.
1 2 | <dt id="MyElement-label"> </dt> <dd id="MyElement-element"><input type="hidden" name="MyElement" value="something" id="MyElement"></dd> |
So to remove the decorator, you can do this after create your hidden element:
1 2 3 4 5 | $id = $form->createElement('hidden', 'id'); $id->removeDecorator('DtDdWrapper'); $id->removeDecorator('HtmlTag'); $id->removeDecorator('Label'); $form->addElement($id); |
This is important because this will prevent to get unwanted result if you add css to your DT/Dd decorator. After remove these decorator, this will print only the input hidden field.
1 | <input type="hidden" name="MyElement" value="something" id="MyElement"> |
With the PhenixApp project, I have decided to extends the default hidden element class to remove decorator of each hidden field indefinitely.
I think this way is better because this prevent some method to be executed for nothing and this is more quick to add hidden field in all my form after.
Here is my class :
1 2 3 4 5 6 7 | class Phenix_Form_Element_Hidden extends Zend_Form_Element_Hidden { public function init(){ $this->setDisableLoadDefaultDecorators(true); $this->addDecorator("ViewHelper"); } } |
Tags: dd, decorator, dt, DtDdWrapper, form decorator, form element, helper, hidden element, hidden field, phenix, remove decorator, Zend Framework, Zend_Form
Related posts:
Tags: dd, decorator, dt, DtDdWrapper, form decorator, form element, helper, hidden element, hidden field, phenix, remove decorator, Zend Framework, Zend_Form
Thank you. Thank You! THANK YOU!!
There is an open bug in the ZF tracker since 1.5RC for this issue…