Changing HTML Output from Zend_Form

I am trying to modify the html obtained by Zend_Form using decorators.

I want the output HTML to look like this:

<form> <fieldset> <legend>Your Details</legend> <dl> <dt>label etc</dt> <dd>input etc</dd> <dt>label etc</dt> <dd>input etc</dd> </dl> </fieldset> <fieldset> <legend>Address Details</legend> <dl> <dt>label etc</dt> <dd>input etc</dd> <dt>label etc</dt> <dd>input etc</dd> ... etc ... </dl> </fieldset> </form> 

I already broke the sections down that I want in certain sets of fields using display groups, for example.

 $this->addDisplayGroup(array('name','email','telephone'),'yourdetails'); $yourdetails= $this->getDisplayGroup('personal'); $yourdetails->setDecorators(array( 'FormElements', 'Fieldset' )); 

This gives me every section sitting inside a set of fields, but every form element now has no dl wrapping, so I have:

 <form> <fieldset> <dt>label etc</dt> <dd>input etc</dd> <dt>label etc</dt> <dd>input etc</dd> </fieldset> ... etc </form> 
0
source share
1 answer

Try the following:

 $yourdetails->setDecorators(array( 'FormElements', array('HtmlTag', array('tag' => 'dl')), 'Fieldset' )); 

It must:

  • Iterate through elements
  • Add a <dl> around the item group
  • Add <fieldset> around <dl>
+2
source

All Articles