How to move red star from the tail of required label to head of the label?

Here is my code:

<?php echo $form->labelEx($model,'password'); ?>

They output html "Password[color="#FF0000"]*[/color]"

However, I’d like to show this as “[color=”#FF0000"]*[/color]Password". How can I do this?

I found that there are Properties afterRequiredLabel and beforeRequiredLabel in CHtml, but I don’t know how to set them.

First of all check source files of CHtml and CActiveForm. You will notice $afterRequiredLabel and $beforeRequiredLabel are public static and you can see their default values. Next in CActiveForm’s labelEx function implementation you can see how activeLabelEx is called. I didn’t checked that myself, but what you want to achieve should be as simple as setting relevant variables before calling functions from CActiveForm.

CHtml::$afterRequiredLabel = '';

CHtml::$beforeRequiredLabel = '<span class="required">your personal super star</span> ';


echo $form->labelEx($model,'password');

It works. Thank you so much.

If this is a universal setting for all your forms you can set globally like this:

class ActiveForm extends CActiveForm


    public function init()



        return parent::init();



where … ? tnx :rolleyes:


for this you need to create a new class/file called ActiveRecord (like the default code generated by Gii does with the Controller)… and all your AR models that need that property should extend from that clas (ActiveRecord instead of CActiveRecord)