如果您添加子表单(称为“Step1”),您将获得以下代码:
<dl class="zend_form">
<dt id="Step1-label"></dt>
<dd id="Step1-element">
<fieldset id="fieldset-Step1" class="Step">
<dl>
.....
</dl>
</fieldset>
</dd>
</dl>
如何在DL标记和DD标记中添加类? 例如:
<dl class="Step1DL">
<dd id="Step1-element" class="Step1DD">
如何使用Zend Decorator进行操作?
再次感谢...
答案 0 :(得分:1)
在模型表单文件中尝试以下代码,
<?php
class Admin_Model_Form_Test extends Zend_Form
{
public $elementDecorators = array(
'ViewHelper',
'Errors',
array(array('data' => 'HtmlTag'), array('tag' => 'dd')),
array('Label', array('tag' => 'dt','class'=>'labmyaccountR'),
));
public $requiredElementDecorators = array(
'ViewHelper',
'Errors',
array('Description',array('escape'=>false,'tag'=>'span', 'placement' => 'append')),
array(array('data' => 'HtmlTag'), array('tag' => 'dd')),
array('Label', array('tag' => 'dt','class'=>'labmyaccountR'),
));
public function EditForm($data = array())
{
$this->setMethod(Zend_Form::METHOD_POST);
$this->setEncType(Zend_Form::ENCTYPE_MULTIPART);
$this->setAction(
$this->getView()->getHelper('url')->url(array(
'controller' => 'test',
'action'=>'edittest'
))
);
$this->setDecorators(array(
'Description',
'FormElements',
'Form'
));
$fnameNotEmpty = new Zend_Validate_NotEmpty();
$fnameNotEmpty->setMessage('Tax value should not be empty');
$fnameStrlen = new Zend_Validate_StringLength(1, 20);
$name = new Zend_Form_Element_Text('taxvalue', array(
'label' => 'Sales Tax *',
'value' => $data['value'],
'class' => 'text-size text',
'tabindex' => '1',
'required' => true,
'validators' => array(
array($fnameNotEmpty, true),
array($fnameStrlen, true)
),
'filters' => array('StringTrim'),
'decorators' => $this->requiredElementDecorators,
));
$name->addValidator('Float',true);
$this->addElement($name);
$submit = new Zend_Form_Element_Submit('submit', array(
'label' => 'Update',
'tabindex' => '20',
'decorators' => $this->elementDecorators,
));
$submit->removeDecorator('Label');
$submit->removeDecorator('label');
$this->addElement($submit);
$id = new Zend_Form_Element_Hidden('tax_id', array(
'value' => $data['tax_id']
));
$id->removeDecorator('label');
$this->addElement($id);
return $this;
}
}
?>
答案 1 :(得分:0)
在创建元素后尝试此操作: 例如:
$element = new Zend_Form_Element_Text('anelement');
$element->addDecorators(array(array('HtmlTag',array('tag' => 'dd', 'class' => 'yourclass' )));