Yii Framework Forum: Showing Error Based On Database Checking - Yii Framework Forum

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

Showing Error Based On Database Checking Rate Topic: -----

#1 User is offline   Aneesh Asokan 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 237
  • Joined: 26-September 12

Posted 14 January 2013 - 01:08 AM

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.
Thanks
Aneesh.
0

#2 User is offline   seenivasan 

  • Master Member
  • PipPipPipPip
  • Yii
  • Group: Members
  • Posts: 620
  • Joined: 17-June 12
  • Location:Chennai,TamilNadu,India.

Posted 14 January 2013 - 02:02 AM

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.
0

#3 User is offline   Aneesh Asokan 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 237
  • Joined: 26-September 12

Posted 14 January 2013 - 02:49 AM

Its not working..
Thanks
Aneesh.
0

#4 User is offline   seenivasan 

  • Master Member
  • PipPipPipPip
  • Yii
  • Group: Members
  • Posts: 620
  • Joined: 17-June 12
  • Location:Chennai,TamilNadu,India.

Posted 14 January 2013 - 02:58 AM

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.
0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users