如何为 zend 表单元素上的标签和错误添加特殊类? [英] how to add special class for labels and errors on zend form elements?

查看:31
本文介绍了如何为 zend 表单元素上的标签和错误添加特殊类?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们如何为 zend-form-element 的标签和错误添加一个特殊的类例如添加类之前的 html 输出代码

how we could add a special class for labels and errors for a zend-form-element for example html output code before add classes

<dt id="username-label"><label for="username" class="required">user name:</label></dt>
<dd id="username-element">
<input type="text" name="username" id="username" value="" class="input" />
<ul class="errors"><li>Value is required and can't be empty</li></ul></dd>

和我们添加类后的代码

<dt id="username-label"><label for="username" **class="req-username"**>user name:</label></dt>
<dd id="username-element">
<input type="text" name="username" id="username" value="" class="input" />
<ul **class="err-username"**><li>Value is required and can't be empty</li></ul></dd>

谢谢

推荐答案

您需要做的是修改 Username 元素的 Label 和 Errors 装饰器:

What you need to do is modify the Label and Errors decorators for the Username element:

My\App\Form.php:

My\App\Form.php:

public function init() {
    // Init form and elements here
    // ...

    $username = new Zend_Form_Element_Text('username');
    $username
        ->setLabel('Username:')
        ->addDecorator('Label', array('class' => 'req-username'))
        ->addDecorator('Errors', array('class' => 'err-username'));

    // ...
}

这篇关于如何为 zend 表单元素上的标签和错误添加特殊类?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆