Anton Abramov
Anton Abramov

Reputation: 2331

Yii CActiveForm validation error

i'm using

echo $form->error($model,'username');

to display validation errors for attribute. But by default it uses div tag with custom class to wrap message itself. I want to use another tag and class. How can i change it?

Upvotes: 2

Views: 3254

Answers (3)

Mamba
Mamba

Reputation: 61

You have two ways of accomplishing your result. You can either use the $errorMessageCssClass property in the definition of the form widget like this:

$form = $this->beginWidget ( 'CActiveForm', array (
'id' => 'test-form',
'enableClientValidation' => true,
'errorMessageCssClass'=>'the error class you want',...........

which will apply to all the elements in your form... OR you can be more specific to an item using:

<?php echo $form->error($model,'password', array('class'=>'your desired class'); ?>

hope it helps

Upvotes: 0

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

Reputation: 8587

You can change the static errorContainerTag of CHtml before you render the errors in your view file:

<?php
CHtml::$errorContainerTag = 'span';

Upvotes: 1

Vasilis Lourdas
Vasilis Lourdas

Reputation: 1179

I suppose that you have to override the error() method of the CActiveForm class. You can also use the errorMessageCssClass class property to change the CSS for the error message.

Upvotes: 1

Related Questions