Zend_Form DLタグの外に送信ボタンを置く

7月 22nd, 2010 by admin Leave a reply »

Zend_Formを使ったページで
DLタグの外にボタンを置いてほしいと要望があったので
設置メモ

DisplayGroupを使ってDLを一つのグループ、
ボタンを未属性のグループとして表現した。

$formには送信ボタン以外のエレメントが設定されていると仮定。

foreach($form->getElements() as $elem){
    $group[] = $elem->getName();
}
$form->addDisplayGroup(
    $group,
    'group'
);
 
$form->addElement( 'button', '_checkButton',array(
            'label'=>'送信確認',
            'type'=>'submit',
    ))
->setElementFilters(array('StringTrim','StripTags'))
->setDescription('<span class="required">&nbsp;</strong> は必須項目です。')
 
 
 
//デザイン
->setDecorators(array(
        'FormElements',
        array('decorator' => 'Description', 'options' => array('tag' => 'p', 'class' => 'description','escape' => false)),
        array('decorator' => 'HtmlTag', 'tag' => 'div' ,'options' => array('class'=>'zend_form')),
        'Form',
    ))
->setDisplayGroupDecorators(array(
        'FormElements',
        array('HtmlTag', array('tag' => 'dl')),
        'Fieldset',
    ))
->setElementDecorators(array(
        'ViewHelper',
        'Errors',
        array('Description', array('tag' => 'p', 'class' => 'description')),
        array('HtmlTag', array('tag' => 'dd')),
        array('Label', 'options' => array('tag' => 'dt','requiredSuffix'=>'<span style="color:red">(※)</span>','escape' => false)),
    ))
->_checkButton->setDecorators(array(
       'ViewHelper',
       array('decorator' => 'HtmlTag','options' => array('class' => 'divSubmit'))
    ));

以下結果

<form enctype="application/x-www-form-urlencoded" action="" method="post">
  <div class="zend_form">
    <fieldset id="fieldset-group">
      <dl>
        <dt><label for="***" class="optional">***</label></dt>
        <dd>$formエレメント要素</dd>
      </dl>
  </fieldset>
  <div class="divSubmit">
    <button name="_checkButton" id="_checkButton" type="submit">送信確認</button>
  </div>
  <p class="description">
    <span class="required">&nbsp;</strong> は必須項目です。
  </p>
</div>
</form>
Advertisement

コメントを残す