开发者

how to add special class for labels and errors on zend form elements?

开发者 https://www.devze.com 2022-12-26 04:51 出处:网络
how we could add a special class for labels and errors for a zend-form-element for example html output code before addclasses

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>

and code after we add classes

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

thanks


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

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'));

    // ...
}


The Label decorator just calls to the view helper formLabel() behind the scenes. You can create your own view helper to override formLabel() to add the class.

0

精彩评论

暂无评论...
验证码 换一张
取 消