[英]How to add id attribute to Zend Framework form?
I have simple class which extends Zend_Form with 2 elements: 我有一个简单的类,它使用2个元素扩展Zend_Form:
class Application_Form_Player extends Zend_Form
{
public function init()
{
$this->addElement('text', 'firstName', array(
'label' => $this->getView()->translate('First name') . ' (' . $this->getView()->translate('imaginary') . ')',
'required' => true,
'filters' => array('StringTrim'),
'validators' => array(array('StringLength', false, array(1, 256)))
)
);
$this->addElement('text', 'lastName', array(
'label' => $this->getView()->translate('Last name') . ' (' . $this->getView()->translate('imaginary') . ')',
'required' => true,
'filters' => array('StringTrim'),
'validators' => array(array('StringLength', false, array(1, 256)))
)
);
}
}
Is there a Zend_Form method that I can use to add "id" attribute to the HTML "dl" created by this class? 是否有Zend_Form方法可用于将“id”属性添加到此类创建的HTML“dl”中?
This is resulting HTML dl to which I want to add id attribute: 这是我想要添加id属性的HTML dl:
<dl class="zend_form">
...
</dl>
$this->setAttrib('id', 'someId');
, this would help you where $this
being the object of your current class. ,这会帮助你
$this
是你当前班级的对象。
$element = new Zend_Form_Element_Text('something');
$element->setAttrib('id','myId')
->setLabel('myLabel')
->setRequired(true);
$this->addElements(array(
$element
));
You can add validators
and filters
with addValidator()
and addFilter()
too. 您也可以使用
addValidator()
和addFilter()
添加validators
和filters
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.