Skip to content

forms fieldset

Harmen Janssen edited this page Aug 11, 2016 · 3 revisions

Wrap elements in a fieldset

Use the addDisplayGroup() method:

$form->addDisplayGroup(
  array(
    'street', 'zipcode', 'city'
  ),
  'address',
  array('legend' => 'Address info')
);

This wraps the elements street, zipcode and city in a display group named address with a legend reading "Address info". A display group is rendered as a fieldset. You can retrieve this display group like this:

$form->getDisplayGroup('address');

Don't like fieldsets? Overwrite its decorator:

$form->addDisplayGroup(
    array(
       'street', 'zipcode', 'city'
    ),
    'address',
    array(
        'decorators' => array(
            'FormElements', 
            array('HtmlTag', array('tag' => 'div'))
        )
    )
);

Some things to note: without the Fieldset decorator (which is one the default decorators) the display group cannot render a legend element. Also, the FormElements decorator renders the elements inside the group, so unless you want to disregard all elements in the group and print an empty container you need that one.

Clone this wiki locally