mrGott
mrGott

Reputation: 1076

Zend_form set Required description

I have a form with Zend_From and my form by default is wrapped by DL, DT and DD tags, and that's fine!

I have to add * <-- this sign to the required fields. First I decided to add explicitly this sign to each form element, but then I couldn't include HTML tags in it so that for example I get <label>My Form Label:<span> *</span></label> so that I can make * <-- this sign of color of red.

Now I found another solution:

$elementDecorators = array(
            'ViewHelper',
            array('Label', array('tag' => 'span', 'escape' => false, 'requiredSuffix' => '<span class="required">* </span>'))
        );

and for each form:

$myElement->setDecorators($elementDecorators);  

and then I tried another approach:

$myElement->getDecorator('label')
          ->setOptions(array('requiredSuffix'=> ' <span class="required">*</span> ', 'escape'=> false));

The problem is that after I apply these code to my form element, it looses DL, DT, DD wrappers. and then looks terrible.

Can you tell me how to add Decorator to label without destroying DL thing?

Upvotes: 0

Views: 88

Answers (1)

RockyFord
RockyFord

Reputation: 8519

I find it very simple to do this with CSS.

dt label.required:before {
    content: "* ";
    color: #ff0000;
}

Upvotes: 2

Related Questions