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

view:





<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'); ?>

</div>



Model:




public function Validateusernamecheck(){  

	

$checkcustomer=Customer::model()->find('LOWER(username)=?',array(strtolower($this->username)))

$checkmerchant=Merchant::model()->find('LOWER(username)=?',array(strtolower($this->username)));

if($checkcustomer || $checkmerchant)

{

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

	return false;	

}

else

	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 } ?>

</div>