我想用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'))
););
);
这两个元素都属于同一组fieldset。 如何让它们在div中进行封装?
答案 0 :(得分:0)
您可以尝试为div open和div close创建自己的表单元素:
MyApp的/形式/元素/ Divopen.php
require_once 'Zend/Form/Element/Xthml.php';
class MyApp_Form_Element_Divopen extends Zend_Form_Element_Xhtml {
public $helper = 'formDivopen';
}
MyApp的/形式/元素/ Divclose.php
require_once 'Zend/Form/Element/Xthml.php';
class MyApp_Form_Element_Divopen extends Zend_Form_Element_Xhtml {
public $helper = 'formDivopen';
}
MyApp的/视图/助手/ 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的/视图/助手/ 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);
不确定这是否是最好的方法,但它可以做到这一点......