views:

88

answers:

3

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?

+5  A: 

They 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:

and Rob Allen's Zend_Form Tutorial:

Gordon
I'd add that they make your form render nicely even without CSS styling :) And also add semantic meaning: "this element in dd (definition) is for username (as is said in dt - definition term) and the whole form is a list of such definitions"
Tomáš Fejfar
+1  A: 
$element->removeDecorator('DtDdWrapper');

OR $element->clearDecorators(); and setting your own decorator;

Alexander.Plutov
+1  A: 

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.

BasTaller