来自 Change HTML output of Zend_Form 中的另一个问题有谁知道我如何生成以下 html 输出? (用 dl 包装每个 dtdd 集)
<form>
<fieldset>
<dl>
<dt>label etc</dt>
<dd>input etc</dd>
</dl>
<dl>
<dt>label etc</dt>
<dd>input etc</dd>
</dl>
</fieldset>
... etc
</form>
最佳答案
给你:
class Default_Form_Chip extends Zend_Form
{
protected $_element_decorators = array(
'ViewHelper',
array(array('data' => 'HtmlTag'), array('tag' => 'dd', 'class' => 'form_element')),
array('Label', array('tag' => 'dt', 'class' => 'required', 'tagClass' => 'form_label')),
array('HtmlTag', array('tag' => 'dl', 'class' => 'form_wrapper')),
);
//put your code here
public function init()
{
$this->setElementDecorators($this->_element_decorators);
$this->setDecorators(array(
'FormElements',
array('HtmlTag', array('tag' => 'fieldset')),
'Form',
));
$this->addElement('text', 'username',array(
'label'=>'Username'
));
$this->addElement('text', 'password',array(
'label'=>'Password'
));
}
}
输出 html:
<form enctype="application/x-www-form-urlencoded" action="" method="post">
<fieldset>
<dl class="form_wrapper">
<dt id="username-label">Username</dt>
<dd class="form_element">
<input type="text" name="username" id="username" value="">
</dd>
</dl>
<dl class="form_wrapper">
<dt id="password-label">Password</dt>
<dd class="form_element">
<input type="text" name="password" id="password" value="">
</dd>
</dl>
</fieldset>
</form>
关于php - Zend Framework - 在 dl 中包装 dt dd,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7620082/