Showing Error Based On Database Checking

I want to show error below the text box based on input value checked with database value.

In the form




<div class="row">

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

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

		<?php echo $form->error($model,'security_ans1'); ?></td>

	</div>

         

	<div class="row buttons">

            <?php  echo CHtml::submitButton('Submit'); ?>               

            



In the controller




if(isset($_POST['Security']))

             {

                 $answer=$_POST['Security']['security_ans1'];

                 if($answer==$ans)

                 {

                     

                      $this->redirect(array('/postRequest/default/index')); 

                 }

                 else

                 {

                    $this->redirect('../../error');

                 }


             }



Now the answer is incorrect it redirect to error page. but i want display error below the text box.

Dear Friend

Check whether the following would serve the purpose.




if(isset($_POST['Security']))

             {

                 $answer=$_POST['Security']['security_ans1'];

                 if($answer==$ans)

                 {

                     

                      $this->redirect(array('/postRequest/default/index')); 

                 }

                 else

                 {  $model=new OurModel;

                    $model->security_ans1=$_POST['Security']['security_ans1'];

                    $model->validate(array(security_ans1));

                    $this->render('view',array('model'=>$model));//the page where the error method resides.

                 }


             }



Not tested the code in my localhost.

Regards.

Its not working…

Dear friend

I am sorry about that.

The idea is to invoke the $model->validate mehod.Then we get the errors assigned to individual attribute.

Then we have to render the form with that $model.

It will be helpful, if you furnish the whole code.

I will try to simulate your scenario, once I get my localhost.

Regards.