yii: submit form posting two times

by prettyscripts on 2011-10-24 16:02

phpxajaxyii

i keep running into the same problem. there are at least 2 rows of data saved everytime a form is saved.

it's because of ajax validation!

if you're using CActiveForm and set enableAjaxValidation to true, when the form is submitted, it will be posting 2x (sometimes more). once for ajax validation and once for submit.

when setting enableAjaxValidation to true, you must also remember to uncomment codes in controller files.

if the controller file is generated by gii, there are 2 lines in form related actions:

PHP:

public function actionSomething() {
     ....
 
    // Uncomment the following line if AJAX validation is needed
    // $this->performAjaxValidation($model);
 
   ...
}

note line 5: uncomment that!