Renderpartial And Ajax Request

Hello. I have a button, when click on which it sends ajax request to controller action and action render partial the view.

The button is in the "view.php". the button is




<?php echo CHtml::ajaxLink(CHtml::image(Yii::app()->theme->baseUrl."/images/edit1.png"), array('player/uurchluh'), 

                        array(

                            'data'=>array('id'=>$model->id),

                            'type'=>'post',

                            'success'=>'js:function(data){

                                    $("div.updateform").append(data);

                                }',

                        ));?>



The controller action is




public function actionUurchluh()

        {

            if(Yii::app()->request->isAjaxRequest)

            {

                $id=$_POST['id'];

                $model=  Player::model()->findByPk($id);

                echo $this->renderPartial('_formUpdate', array('model'=>$model));

            }

        }



The "uurchluh.php" view which is partial rendered is




<?php $form=$this->beginWidget('CActiveForm',

        array(

            'id'=>'update-player',

            'enableClientValidation'=>true,

            'action'=>CHtml::normalizeUrl(array('player/update')),

        ));?>

    <div class="updateRow">

        <label class="genericLabel"><?php echo $attr['tovchlol']?>:</label>

        <?php echo $form->textField($model,'tovchlol', array('size'=>5,'maxlength'=>5, 'class'=>'genericInput'))?>

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

    </div>

    <div class="updateRow">

        <label class="genericLabel"><?php echo $attr['ovog']?>:</label>

        <?php echo $form->textField($model,'ovog',array('size'=>20,'maxlength'=>20, 'class'=>'genericInput')); ?>

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

    </div>

    <div class="updateRow">

        <label class="genericLabel"><?php echo $attr['ner']?>:</label>

        <?php echo $form->textField($model,'ner',array('size'=>20,'maxlength'=>20, 'class'=>'genericInput')); ?>

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

    </div>

    <div class="updateButtons">

        <?php echo CHtml::submitButton("Save", array('class'=>'saveUpdate'));?>

    </div>

    <?php $this->endWidget();?>



The form is submitted to player/update action. When form is submitted and if there are validation errors, how to render form errors in the "view.php"?

Take a look at this wiki.

You can also use this really fresh extension.

IMO, you should handle user’s submission in actionUurchluh (player/uurchluh) instead of passing it to player/update. Then after call $model->validate() (in controller), you can get errors by $model->getErrors(); (in view)

Or another solution, your form calls ajax request to player/update, then player/update returns validation result. But it’s will be more complicated, (clicking button requests form by ajax, form requests validation by another ajax)

Still i don’t know how to do this. I handle user’s submission in actionUurchluh, and there are validation errors,

how go back to page on which there is form, and display errors. On the page ajax request is triggered and display a form.