Romoving unnecessary dt and dd’s in Zend
Posted by Faheem Abbas on November 5, 2008
Few days back I come across a new problem.
Zend by default wrap some form elements like display groups and form itself in
dt and dd. this disturb the entire page layout.
I tried different ways to change this default behavior. After googling for lot of time I found a simple solution.
just try this
$form->removeDecorator(“DtDdWrapper”);
similarly
$displayGroupName->removeDecorator(‘DtDdWrapper’);
you can remove DtDWrapper’s from all elements using this magic method-removeDecorator(“DtDdWrapper”);
Some time you want to remove label from your form element. so try this one
$element->removeDecorator(“Label”);
that’s it. enjoy.
Surt said
Hi, i was triying to remove all dl dd dt markup on the forms, (i still can’t understand why this markup by default on zend_form).
Using :
$this->removeDecorator(‘HtmlTag’);
$this->removeDecorator(‘DtDdWrapper’);
$this->groupname->removeDecorator(‘DtDdWrapper’);
i can remove “dt dd” for the fieldset and the “dl dd dt” for the form, but my elements still have “dd dt” can i remove it from ALL the elements at a time?
I don’t want to define my own decorator for the elements, i fear to destroy some important features for file inputs, etc.. just want to remove “dd dt” markup.
Must i remove it from each element?
Faheem Abbas said
To remove decorators from all form elements, write
foreach($form->getElements() as $element) {
$element->removeDecorator(‘DtDdWrapper’);
$element->removeDecorator(‘Label’);
}
Surt said
Thanx a lot Faheem Abbas, getElements! good one.
Anyway, removing dtdWrapper on my elements does nothing, i did:
$element->removeDecorator(‘HtmlTag’)
->removeDecorator(‘Label’)
->addDecorator(‘Label’);
removing and adding label to destroy the tag, no way using tag=” or null or false
why in the hell Zend developers are putting a (x)html markup on my programming libraries!
heik said
“Zend by default wrap some form elements like display groups and form itself in dt and dd. this disturb the entire page layout.”
–> you mean this stupid “intend-like” movement of input fields!? I had the same problem and solved it as follows:
- created own decorator called My_Decorator_FormElements extends Zend_Form_Decorator_FormElements
- just added one method: public function render($content) { return “” . parent::render($content).”"; }
- in Form class: $this->addPrefixPath(‘My_Decorator’, ‘My/decorator’, ‘decorator’);
-> Zend_Form now uses My Decorator for FormElements:
The Form wraps the missing “” around the Elements and the intend is gone
Cheers,
heik
heik said
… oops .. got filtered out -> “The Form wraps the missing dl tags around the Elements and the intend is gone”