Double Records Added After Enabling Client Side Validation And Submitting form in Yii

I have a following simple form in Yii that is submitted by AJAX:

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

        'id' => 'application-form',

        'enableAjaxValidation' => true,

        'enableClientValidation' => true,

        'htmlOptions' => array(

            'enctype' => 'multipart/form-data',

            'onsubmit'=>"return send();"



)); ?>

<div class="row">

        <?php echo $form->labelEx($model, 'name'); ?>

        <?php echo $form->textField($model, 'name', array('size' => 60,'maxlength' => 255)); ?>

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


<div class="row buttons">

        <?php echo CHtml::submitButton($model->isNewRecord ? 'Create' : 'Save'); ?>


And function for submitting (this is how I need it to be, without using ajaxSubmitButton):

function send (){

var data_form=$("#application-form").serialize();


    type: "POST",

    url: "<?php echo Yii::app()->createUrl('admin/application/create') ?>",


    data: data_form,

    success: function (data, textStatus, jqXHR) {




    error: function (jqXHR, textStatus, errorThrown) {

       // console.log( errorThrown);



return false;


My create controller:

public function actionCreate()


        $model = new Application;



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

           if ( $model->save()){

                echo CJSON::encode(array('success' => 'true','id'=>$model->id));




        $this->render('create', array(

            'model' => $model



Filed name is required and that is only validation for now. When I try to submit form without field name inputted, validation messages appear as they supposed to do in Yii. But when I fill form correctly, my model is inputted twice in database. If I remove following property:


model gets saved correctly (only one time), but no validation messages appear.

How can I get default validation messages in Yii to appear, when I submit my form via ajax and model not to be saved twice. I need to submit form this way, because I will return model id in Ajax response for processing in JavaScript.

I searched the web for this and tried all suggestions, but none of them work.

Thank you all so much!

Update: I solved this by adding

'afterValidate'=>'js:function(form,data,hasError){ send(form,data,hasError);

and removing

'onsubmit'=>"return send();"

line. Now it shows validation errors and only saves model once. Check this post for more info.