how to customize html of form error message?

hello again, i want to know how to customize the html of the error messages in forms.

i have looked over the forums and have not found anything, i have read tons of documentation, and all that i got was

but nowhere did i find a example of how to use this $htmlOptions.

in a form, i got the custom error messages out by using

CHtml::error($form, 'username', array('class'=>'error'))

i have managed to customize its class to be called error instead of errorMessage

but i dont know how to make the tag into a <span> instead of a <div>

and i also want more tags in it because of the css that i used.

now the error message looks like this

<div class="error">Username required.</div>

i need this

<span class="error"><b>Username required.</b></span>

any help greatly appreciated.

Via css



   display: inline;

   font-weight: bold;


might do the same thing.

what about the b?

<span class="error"><b>Username required.</b></span>

the b is a dummy tag, it does not serve to make the text bold, it serves for css positioning (i think i should have mentioned this at the start).

plus its not the css that i need, im using div’s for other purposes, and the span serves more as a selector in the current css, not to confuse other error classes, i mean i can change it in the css, but i would like to know first if its possible to do it in yii.

I’m pretty sure <b> stands for bold. None of the tags are there only for css positioning.

It’s also a fact you can set CHtml properties to customize enclosing text.

i meant positioning as in i use the class="error" to make a fluid full width transparent block, to which i add a right aligned <b> tag with all the styling, backgrounds and margins etc… also its not a question of why i need it.

here is a bit of the css… so you see what i mean.

span.error {











span.error b {



	padding:1px 10px 1px 10px;




yes, thats what im asking for, i know it can be done, i just need some small example! :S

it seems that yii can’t do that… ill have to work around this limitation.

You can always create widget for this purpose. Look at the code of CHtml::error to see and copy with the modification you need.

Extending this static class is not so good ideas as creating widget, I think.

thats pretty much what i did

	public function formError($model,$attribute,$html='') {

			$formError = $model->getError($attribute);


				if (!empty($html)){

					return str_replace('{error}',$formError,$html);

				} else {

					return $formError;


			} else {

				return '';