简体   繁体   English

如何将id属性添加到Zend Framework表单?

[英]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()添加validatorsfilters

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何在Zend Framework 2.2.4中为表单元素添加类和id - How to add class and id to form element in Zend Framework 2.2.4 如何使用zend中的zend在zend Framework 2中添加自定义属性 - How add custom attribute in zend framework 2 using zend from 如何在Zend Framework 2中向表单添加错误消息? - How to add an error message to the form in Zend Framework 2? 如何在Zend框架2中向使用Zend / Form生成的标签添加属性 - How to add attributes to a label generated with Zend/Form in Zend framework 2 如何在Zend Framework中将路由添加到此类url / index / viewmodel / id / {id} / - How to add route to such url /index/viewmodel/id/{id}/ in Zend Framework 如何在Zend Framework 2表单的第一个<option>上将disabled属性设置为disabled - How to set the disabled attribute as disabled on the first <option> of a Zend Framework 2 form Zend Framework 2 - 添加Form类 - Zend Framework 2 - Add Form class 如何为Zend_Form_Element_MultiCheckbox id属性设置分隔符? - How to set separator for Zend_Form_Element_MultiCheckbox id attribute? 如何在Zend Framework 1.9中向标签标签添加ID? - How do I add an ID to a label tag in Zend Framework 1.9? 在 Zend Framework 3 中填充表单元素的标签或属性 - Populate label or attribute of form element in Zend Framework 3
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM