This question is specific to Zend_Form. Zend_Form adds standard decorators such as <dd> <dt> <dl>
. What do I lose if I were to remove them? Are they used by Zend_Form itself for error reporting or any other reason?
views:
88answers:
3They are solely for structuring the output of your Zend Form elements in a definition list. Whether your form renders errors is controlled through the Error Decorator.
See this series of articles by Matthew Weier O'Phinney:
- The simplest Zend Form Decorator
- How to layer Decorators
- Rendering Zend Form Decorators individually
- Creating composite elements
and Rob Allen's Zend_Form Tutorial:
$element->removeDecorator('DtDdWrapper');
OR
$element->clearDecorators();
and setting your own decorator;
1) It's simplest and maybe the best practice to change appearance of forms via CSS, not by markup (by writing your own decorators), at least, when you're not experienced-well programmer.
By removing DdDt decorator, lots of possibilities of CSS, such as input fields/labels/error-lists positioning, coloring, indenting and so on are lost.
For example, to <dt>
or <dd>
you can add own class in form initialization, which later can be styled, satisfying your specific needs.
See code:
$comment = $this->createElement('textarea','comment',array(
'label'=>'Post a comment',
'required'=>true
))
->setDecorators(array(
'ViewHelper',
'label',
'Errors',
array(
'HtmlTag',
array(
'tag' => 'dd',
'class'=>'elevatedField'
)
)
))
;
Now in CSS stylesheet in .elevatedField{}
rule you may define specific look for this textarea field.
Actually, this example is not for default DdDt decorator, but it's explaining well ways of utilizing <dd>
tag. Almost the same is for default DdDt decorator.
Look here what can be achieved with only css: http://robertbasic.com/blog/styling-the-default-zend_form-layout/ And it's not a limit.
2) Semantics of html markup is lost too, which almost have no meaning, at least for today.
Also, DdDt are not used by Zend_Form itself for error reporting - there is another standard decorator named 'Errors' for this needs.