1

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 Answer 1

3

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>
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.