如何将id属性添加到Zend框架表单



我有一个简单的类,它用 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)))
            )
        );
    }
}

是否有一种Zend_Form方法可用于将"id"属性添加到此类创建的 HTML "dl"中?

这是生成的HTML dl,我想在其中添加id属性:

<dl class="zend_form">
...
</dl>

$this->setAttrib('id', 'someId');,这将有助于您在哪里$this成为当前类的对象。

$element = new Zend_Form_Element_Text('something');
$element->setAttrib('id','myId')
->setLabel('myLabel')
->setRequired(true);
$this->addElements(array(
     $element
));

您也可以使用addValidator()addFilter()添加validatorsfilters

最新更新