Yii: AJAX validation and Duplicated data

When creating a new record, I noticed the new record is duplicated (usually 3x but sometimes 4x, 5x…) It took me a while to realize this is caused by AJAX validation.

There are 2 things needed to be done from the code generated by Gii, if you want AJAX validation.

In the view file, set enableAjaxValidation property to true.

In the controller file, locate actionCreate(). you will notice the following 2 lines from the code generated by Gii:

// Uncomment the following line if AJAX validation is needed
// $this->performAjaxValidation($model);

Yes, just follow this instruction. uncomment it.

3 thoughts on “Yii: AJAX validation and Duplicated data

  1. Birger Reply

    Thanks, I had problems with this as well. Although I still would like to know what causes this behaviour…

Leave a Reply

Your email address will not be published. Required fields are marked *