我有这样的表格:
class Request_Form_Prova extends Zend_Form
{
public function init()
{
$this->setMethod('post');
$SubForm_Step = new Zend_Form_SubForm();
$SubForm_Step->setAttrib('class','Step');
$this->addSubform($SubForm_Step, 'Chicco');
$PrivacyCheck = $SubForm_Step->createElement('CheckBox', 'PrivacyCheck');
$PrivacyCheck->setLabel('I have read and I agre bla bla...')
->setRequired(true)
->setUncheckedValue('');
$PrivacyCheck->getDecorator('Label')->setOption('class', 'inline');
$SubForm_Step->addElement($PrivacyCheck);
$SubForm_Step->addElement('submit', 'submit', array(
'ignore' => true,
'label' => 'OK',
));
}
}
生成此HTML:
<form enctype="application/x-www-form-urlencoded" method="post" action="">
<dl class="zend_form">
<dt id="Chicco-label"> </dt>
<dd id="Chicco-element">
<fieldset id="fieldset-Chicco" class="Step">
<dl>
<dt id="Chicco-PrivacyCheck-label"><label for="Chicco-PrivacyCheck" class="inline required">I have read and I agre bla bla...</label></dt>
<dd id="Chicco-PrivacyCheck-element">
<input type="hidden" name="Chicco[PrivacyCheck]" value=""><input type="checkbox" name="Chicco[PrivacyCheck]" id="Chicco-PrivacyCheck" value="1">
</dd>
<dt id="submit-label"> </dt>
<dd id="submit-element">
<input type="submit" name="Chicco[submit]" id="Chicco-submit" value="OK">
</dd>
</dl>
</fieldset>
</dd>
</dl>
</form>
如何向class="Test"
元素添加<dd id="Chicco-element">
?
为了得到它:<dd id="Chicco-element" class="Test">
我认为是这样的,但是它不起作用:
$SubForm_Step->getDecorator('DdWrapper')->setOption('class', 'Test');
或
$SubForm_Step->getDecorator('DtDdWrapper')->setOption('class', 'Test');
我该怎么做? 如何将SubForm的DD和DT元素包装在另一个DL元素中?
就像那样:
<dl class="zend_form">
<dl>
<dt id="Chicco-label"> </dt>
<dd id="Chicco-element">
<fieldset id="fieldset-Chicco" class="Step">
<dl>
.......
答案 0 :(得分:0)
您无法以这种方式添加课程。从第67行开始查看Zend_Form_Decorator_DtDdWrapper
的源文件:
return '<dt id="' . $elementName . '-label">' . $dtLabel . '</dt>' .
'<dd id="' . $elementName . '-element">' . $content . '</dd>';
您可以使用自己的类扩展装饰器,并重写render方法以将类添加到标记中。