Change Which Element Gets Error Class After Validation

Hi everyone,

In my forms instead of:






I use:








When there’s a validation error, the error class is added to <div> and the label remains unaltered. What is a neat way to make the label red too? I figure it can be done by changing the validation algorithm to add the error class to <li> instead of <div> and then altering styles accordingly.

Hi my friend

If I understood you want to make a style for label when error occurs

According to

you could check if error exists by


or for general error you can use



if ($model->hasErrors('your_attribute')) {

echo '<label style="color:red">';

} else {

echo '<label>';



<?php $form=$this->beginWidget('CActiveForm', array(




)) ?>

Thanks! The trick with inputContainer worked. I had to alter styles a bit and now in case of client validation error <li> receives the error class and the label becomes red.