Question

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?

Was it helpful?

Solution

I find it very simple to do this with CSS.

dt label.required:before {
    content: "* ";
    color: #ff0000;
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top