How Can I Display My Own Error Messages Below Text Field In Forms

i have a problem in my own validator it does not display any error message

here is the code


<div class="row">

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

<?php echo $form->textField($model,'username',array('class'=>'signupField'),array('size'=>50,'maxlength'=>50)); ?>

<?php echo $form->error($model,'usernamecheck'); ?>



public function Validateusernamecheck(){  




if($checkcustomer || $checkmerchant)


	echo $this->addError('username',' Username Already Exists try another user name ');

	return false;	



	return true;


it just catches the error the textbox becomes red but it don’t show the message below the text box what is wrong here kindly help plzz

Why you’re using usernamecheck instead of username?

i have 2 tables in database merchant and customer and i want the user name to be unique

put the following code where you want to show the errors:::

<?php echo $form->errorSummary($model); ?>

it show errors all at once at the top of the form i want to show the error below that text field

Using below code, We can get the individual error by attribute name of form

<div class="row">

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

	<?php echo $form->textField($model,'name'); ?>

       <?php $errors=$model->getErrors("institutionnametxtid");

             if(count($errors)>0){ ?>                    

           <div class="errorMessage">Username  "<?php echo $model->text_institutename; ?>" has already been taken.</div>

       <?php } ?>