Problem With Cjuidialog And Ajaxsubmitbutton

I created dialog like in

What i do to get error:

I open dialog (append record) and close it with close button

I open same dialog again and press submit button

Then Addnew action called twice and model saved (appended in database) twice too.

Same behavior if i open dialog, press submit, then open it again, press submit. I get second record created twice because addnew called twice.

Some background:

I used Yii 1.1.8 about year ago. All worked well until i upgraded to yii 1.1.12. I checked it with old version of yii and it works.

I checked upgrade instructions but not found anything than can apply to my case.

Below i show code i use. Sorry for long post and ugly english.



public function actionAddnew() {

        $model=new Test;

        // Ajax Validation enabled


        // Flag to know if we will render the form or try to add new jon.


        if(isset($_POST['Test'])) {       




            if($model->save()) {

                echo $this->renderPartial('_viewCompact',array('data'=>$model,),false,true);



        if($flag) {

            $headers = getAllHeaders();

            $model->EDUCATIONINF_ID = $headers['EDUCATIONINF_ID'];

            Yii::app()->clientScript->scriptMap['jquery.js'] = false;




create dialog button:

    echo CHtml::ajaxButton(Yii::t('Test','Внутренний экзамен'),



            'onclick'=>'$("#testDialog").dialog("open"); return false;',


            'beforeSend'=>'function(xhr) {

                xhr.setRequestHeader("EDUCATIONINF_ID", document.getElementById("EDUCATIONINF_ID").value);












            'title'=>Yii::t('Test','Добавить внутренний экзамен'),









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



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



)); ?>

    <?php echo $this->renderPartial('__subform', array('form'=>$form,'model'=>$model,'addButtons'=>false,'Hidden'=>true)); ?>


    <div class="row buttons">


            echo CHtml::ajaxSubmitButton(Yii::t('Test','Добавить внутренний экзамен'),


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








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