Change HTML output of Zend_Form

血红的双手。 提交于 2019-12-13 01:38:08

问题


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:

  1. Iterate through the elements
  2. Add a <dl> around the group of elements
  3. Add a <fieldset> around the <dl>


来源:https://stackoverflow.com/questions/2148406/change-html-output-of-zend-form

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!