Mallika Iyer
Mallika Iyer

Reputation: 710

How to display 2 display groups in the same div in a zend form?

How can I display more than 1 display group WITHIN a div?

I simply need to show a visual separation - but within the same div.

Is there a way to show more than 1 display group within a div?

for example: to achieve the following in zend forms:

  <div style="width: 100%;">     

       <div style="width: 50%; float: left; padding-left: 20px; padding-bottom: 25px;">
       <fieldset id="fieldset-homeAddressSettings" tag="fieldset" style="">
         <legend> Home address </legend>
        <!-- multiple elements follow -->
        </fieldset>
       </div>
      <div style="width: 50%; float: left; padding-left: 20px; padding-bottom: 25px;">
     <fieldset id="fieldset-officeAddressSettings" tag="fieldset" style="">
         <legend> Office address </legend>
        <!-- multiple elements follow -->
     </fieldset>  
       </div>
  </div>

How can I achieve this in Zend forms?

I have searched and searched and i have not found anything useful so far.

Upvotes: 2

Views: 4987

Answers (2)

Ankit Aggarwal
Ankit Aggarwal

Reputation: 1546

The 'openOnly' and 'closeOnly' boolean options for the 'HtmlTag' decorator do exactly what you need to do. What openOnly means, as you can figure out, is that it only generates an opening tag (i.e. ) without the closing tag, and vice-versa for the closeOnly attribute (i.e.

Zend_Form PHP code:

$form = new Zend_Form();

// Form stuff here

$form->addDisplayGroup(
    array(
        'homeAddressLine1',
        'homeAddressLine2',
        'homeCity',
        // etc
    ),
    'homeAddress',
    array(
        'legend' => 'Home Address'
        'disableDefaultDecorators' => true,
        'decorators' => array(
            'FormElements',
            'FieldSet',
            array('HtmlTag', array('tag' => 'div', 'class' => 'addresses', 'openOnly' => true))
        )
    )
);

$form->addDisplayGroup(
    array(
        'workAddressLine1',
        'workAddressLine2',
        'workCity',
        // etc
    ),
    'workAddress',
    array(
        'legend' => 'Work Address'
        'disableDefaultDecorators' => true,
        'decorators' => array(
            'FormElements',
            'FieldSet',
            array('HtmlTag', array('tag' => 'div', 'closeOnly' => true))
        )
    )
);

Generated HTML:

<form <!-- Your Zend_Form attributes here -->>
    <div class="addresses">
        <fieldset id="fieldset-homeAddress">
            <legend>Home Address</legend>
            <!-- Your Home Address elements/decorators here -->
        </fieldset>
        <fieldset id="fieldset-workAddress">
            <legend>Work Address</legend>
            <!-- Your Work Address elements/decorators here -->
        </fieldset>
    </div>
</form>

Upvotes: 8

Mallika Iyer
Mallika Iyer

Reputation: 710

I worked this one out with JavaScript - it has convinced me that while zend form is good for somethings, its not always the best option. sometimes its just more pain than its worth.

Upvotes: 1

Related Questions