如何以zend形式在同一div中显示2个显示组?

时间:2010-02-04 18:02:34

标签: zend-framework zend-form zend-decorators

如何在div中显示多个显示组?

我只需要显示视觉分离 - 但在同一个div中。

有没有办法在div中显示多个显示组?

例如:以zend形式实现以下目标:

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

如何以Zend形式实现这一目标?

我搜索过并搜索过,到目前为止我还没有找到任何有用的东西。

2 个答案:

答案 0 :(得分:7)

'HtmlTag'装饰器的'openOnly'和'closeOnly'布尔选项正是您需要做的。正如你可以想象的那样,openOnly意味着它只生成一个没有结束标记的开始标记(即),反之亦然,因为closeOnly属性(即

Zend_Form PHP代码:

$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))
        )
    )
);

生成的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>

答案 1 :(得分:1)

我用JavaScript编写了这个 - 它让我确信虽然zend形式对某些人有好处,但它并不总是最好的选择。有时它比它的价值更痛苦。