问题
I'm trying to change the html outputted by Zend_Form using decorators.
I want the outputted 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've already broken the sections down i want within specific fieldsets using display groups, e.g.
$this->addDisplayGroup(array('name','email','telephone'),'yourdetails');
$yourdetails= $this->getDisplayGroup('personal');
$yourdetails->setDecorators(array(
'FormElements',
'Fieldset'
));
This gives me each section sitting within a fieldset but each form element is now lacking a wrapping dl so what i have is:
<form>
<fieldset>
<dt>label etc</dt>
<dd>input etc</dd>
<dt>label etc</dt>
<dd>input etc</dd>
</fieldset>
... etc
</form>
回答1:
Try this:
$yourdetails->setDecorators(array(
'FormElements',
array('HtmlTag', array('tag' => 'dl')),
'Fieldset'
));
That should:
- Iterate through the elements
- Add a
<dl>
around the group of elements - Add a
<fieldset>
around the<dl>
来源:https://stackoverflow.com/questions/2148406/change-html-output-of-zend-form