views:

266

answers:

2

hello 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" name="username" id="username" value="" class="input" />
<ul **class="err-username"**><li>Value is required and can't be empty</li></ul></dd>

thanks

A: 

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.

smack0007
+1  A: 

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

    // ...
}
Ankit Aggarwal
thanks for your reply it adds class with "req-username optional" namecan add a name with out "optinal"?
user1400