When Ajaxvar Initialized In Cactiveform [Solved]

About CActiveForm in document is:(clientOptions section)

Now take a look in my example: Summary: i have a form with two fields mail and newEmail, i submitted form via ajaxSubmitButton(if you need form code tell me put it). In following i get var_dump($_POST) content in two state:

First: Following var_dump($_POST) is for when a field(newEmail) is left empty:


array

'User' =>

    array

    'email' => string 'user@gmail.com' (length=14)

    'newEmail' => string '' (length=0)

Second: Following var_dump($_POST) is for when all the fields are filled:


array

'User' =>

    array

    'email' => string 'user@gmail.com' (length=14)

    'newEmail' => string 'admin@minudasht.net' (length=19)

'ajax' => string 'email-form' (length=10)

'yt0' => string 'update' (length=18)

As you see only when all fields are filled the ajaxVar(ajax) exist in $_POST. When ajaxVar(ajax) initialized in CActiveForm?

Can you share the code you’re using to generate the form?

[b]email-form:

[/b]




<?php

<div class="form">

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

        	'id'=>'email-form',

        	'enableAjaxValidation'=>true,

    	'clientOptions'=>array(

            	'validateOnSubmit'=>true,

            	'focus'=>'input[type="email"]:first',

        	)

    	)); ?>


    	<div class="row">

        	<?php echo $form->label($model,'email') ?>

        	<?php echo $form->textField($model,'email') ?>

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

    	</div>


    	<div class="row">

        	<?php echo $form->label($model,'newEmail') ?>

        	<?php echo $form->textField($model,'newEmail') ?>

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

    	</div>

    	<hr>

    	<div class="row">

        	<?php  echo CHtml::ajaxSubmitButton(

            	'update',

            	Yii::app()->createUrl('upanel/user/CEmail'),

            	array(

                	'dataType'=>'json',

                	'type' => 'POST',

                	'data' => "js:$('#email-form').serialize()",

                	'success'=>'function(data){

                    	if(data.status=="success")

                    	{

                        	//alert(data.status);

                        	hideFormErrors(form="#email-form");

                        	callback(status=data.status);

                    	}else{

                        	formErrors(data,form="#email-form");

                    	}

                	}',


                	'beforeSend'=>'before',

            	),

            	array(

                	'id' => 'update-button'.uniqid(),

                	'class'=>'submit-button'

            	)

        	);

        	?>

    	</div>

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

</div> 

<?php echo $form->errorSummary($model,'please solve following errors:') ?>



Here i understand what when ajaxVar initialized. When [color="#0000FF"]‘validateOnSubmit’=>true[/color] is set ajaxVar initialized onsubmit, and when[color="#0000FF"] validateOnChange=>true[/color] is set ajaxVar initialized on changing fileds.

[size="3"]Edit:[/size]

Useful Link.