arun
arun

Reputation: 3677

How to customize error display messages in Yii?

How to customize error display messages in yii? for example I need to display my error messages like below

div class="error-left"></div>
<div class="error-inner">This field is required.</div>

I can obtain the second div by applying class "error-inner" to the htmlOptions of $form->error(..).

<?php echo $form->error($model,'category_title',array('class'=>'error-inner')); ?>

But how can I display the first div before that?

Upvotes: 0

Views: 4178

Answers (1)

Michael H&#228;rtl
Michael H&#228;rtl

Reputation: 8587

You can't with Yii's default components. But you still could create your custom CActiveForm class and override the error() method, to add your custom HTML there.

<?php
class MyActiveForm extends CActiveForm
{
    public function error($model,$attribute,$htmlOptions=array(),$enableAjaxValidation=true,$enableClientValidation=true)
    {
        $html = '<div class="error-left"></div>';
        $html .= parent::error($model, $attribute, $htmlOptions, $enableAjaxValidation,$enableClientValidatin);
        return $html;
    }
}

Upvotes: 3

Related Questions