php - stay on the same page after error validation in yii -


i avoid redirecting after error validation.

i display list of post , each post user can give comment after clicking on button.

this display comment form under choosen post.

if there error in validation of comment want stay on page , display errors beside field in error (as default).

here my controller action comment

public function actioncreate()     {         $model=new comment;          if(isset($_post['comment']))         {             $model->attributes=$_post['comment'];              if($model->save()) {                 $this->redirect(yii::app()->request->urlreferrer);              } else {                   yii::app()->end();              }         }          $this->render('create',array(             'model'=>$model,         ));     } 

and view

<div class="form">  <?php $form=$this->beginwidget('cactiveform', array(     'id'=>'comment-form',     'enableclientvalidation'=>true, )); ?>      <p class="note">fields <span class="required">*</span> required.</p>      <?php echo $form->errorsummary($model); ?>      <div class="row">         <?php echo $form->labelex($model,'comment'); ?>         <?php echo $form->textfield($model,'comment',array('size'=>60,'maxlength'=>140)); ?>         <?php echo $form->error($model,'comment'); ?>     </div>      <div class="row buttons">         <?php echo chtml::submitbutton($model->isnewrecord ? 'create' : 'save'); ?>     </div>  <?php $this->endwidget(); ?>  </div><!-- form -->  

for moment, yii::app()->end(); shows blank page, if dont nothing in else part , continues , displays create view (loosing decoration)

---adding more information

actually, have in page this

post 1 (comment form) commment  :   ........ save  post 2  post 3 

when click on save without comment, want stay in page, giving user possibility see error (comment missing) , save again.

can tell me mistake?

thank help

in else block have tell yii render same page again. after calling $model->save() errors in model. before yii::app()->end(); call rendering of page $this->render('create',array('model'=>$model,));


Comments

Popular posts from this blog

get url and add instance to a model with prefilled foreign key :django admin -

css - Make div keyboard-scrollable in jQuery Mobile? -

ruby on rails - Seeing duplicate requests handled with Unicorn -