0

我想用div标签封装两个元素,我想要这样

 <div>
    <span id="mailRecepientName2-label">
      <label class="elementTitle required" for="mailRecepientName2">اسم المستفيد</label>
    </span>
    <span>
       <input id="mailRecepientName2" type="text" value="" name="mailRecepientName2">
    </span>
    <span id="mailRecepientNote2-label">
        <label class="required" for="mailRecepientNote2">البيـــــــان</label>
    </span>
    <span class="largeText">
      <input id="mailRecepientNote2" type="text" value="" name="mailRecepientNote2">
   </span>
    <a class="ico_lable_remove" data-recepeintcount="2" name="deleteNewRecepient" href="javascript:void(0)"></a>
 </div>

我这样弄

    $mailRecepientName = new Zend_Form_Element_Text("mailRecepientName" . $id);
    $mailRecepientName->setRequired(true)->setLabel('اسم المستفيد')->setDecorators(array(
            'ViewHelper',
            'Errors',
            array(array('data' => 'HtmlTag'), array('tag' => 'span')),
            array('Label', array('tag' => 'span'))
        ););

    $mailRecepientNote = new Zend_Form_Element_Text("mailRecepientNote" . $id);
    $mailRecepientNote->setRequired(true)->setLabel('البيـــــــان')->setDecorators(array(
            'ViewHelper',
            'Errors',
            array(array('data' => 'HtmlTag'), array('tag' => 'span')),
            array('Label', array('tag' => 'span'))
        ););
      );

这两个元素都属于同一组字段集。如何使它们封装在 div 中?

4

1 回答 1

0

您可以尝试为 div open 和 div close 创建自己的表单元素:

MyApp/Form/Element/Divopen.php

require_once 'Zend/Form/Element/Xthml.php';
class MyApp_Form_Element_Divopen extends Zend_Form_Element_Xhtml {

public $helper = 'formDivopen';
}

MyApp/Form/Element/Divclose.php

require_once 'Zend/Form/Element/Xthml.php';
class MyApp_Form_Element_Divopen extends Zend_Form_Element_Xhtml {

public $helper = 'formDivopen';
}

MyApp/View/Helper/FormDivopen.php

require_once 'Zend/View/Helper/FormElement.php';
class MyApp_View_Helper_FormDivopen extends Zend_View_Helper_FormElement {
public function formDivopen($name, $value = null, $attribs) {
$info = $this->_getInfo($name, $value, $attribs);
extract($info);
$xhtml = '<div'
    . ' name="'. $this->view->escape($name) . '"'
    . ' id="'. $this->view->escape($id) . '"'
    . ' value="'. $this->view->escape($value) . '"'
    . $this->_htmlAttribs($attribs)
    . '>';
return $xhtml
}
}

最后:MyApp/View/Helper/FormDivclose.php

require_once 'Zend/View/Helper/FormElement.php';
class MyApp_View_Helper_FormDivclose extends Zend_View_Helper_FormElement {
public function formDivclose($name, $value = null, $attribs) {

$xhtml = '</div>';
return $xhtml
}
}

然后以您的形式:

$divOpen = $this->createElement('divopen', 'divname');
$this->addElement($divOpen);

$mailRecepientName = new Zend_Form_Element_Text("mailRecepientName" . $id);
$mailRecepientName->setRequired(true)->setLabel('اسم المستفيد')->setDecorators(array(
        'ViewHelper',
        'Errors',
        array(array('data' => 'HtmlTag'), array('tag' => 'span')),
        array('Label', array('tag' => 'span'))
    ););

$mailRecepientNote = new Zend_Form_Element_Text("mailRecepientNote" . $id);
$mailRecepientNote->setRequired(true)->setLabel('البيـــــــان')->setDecorators(array(
        'ViewHelper',
        'Errors',
        array(array('data' => 'HtmlTag'), array('tag' => 'span')),
        array('Label', array('tag' => 'span'))
    ););
  );

$divClose = $this->createElement('divclose', 'closingdiv');
$this->addElement($divClose);

不确定这是否是最好的方法,但它可以解决问题......

于 2012-06-26T18:29:26.590 回答