Ajaxsubmitbutton In Cactiveform

Hi everybody,

after spending hours reading about the issues with the ajaxSubmitButton here in the forum without finding a solution for my problem, I am going to describe it here.

I have successfully implemented a ajax-request as described here:

CJuiDialog for create new model and I make use of the code described here:

Working with CGridView in Admin Panel

In the latter POST data is passed with an ajaxSubmitButton to a controller-action and this works fine. In the former data is sent from the controller-action and this works fine either. But when I want to put it alltogether no POST-data is passed to the controller anymore.

My code looks like this:


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

'id' => 'product-form',



$this->widget('zii.widgets.grid.CGridView', array(







            'selectableRows' => '100',   







				'url'=>'Yii::app()->controller->createUrl(\'product/update\', array(\'id\'=>$data["id"]))',





// This button works fine

echo CHtml::ajaxSubmitButton('Delete',


array('beforeSend'=>'function() { if(confirm("Are You Sure ...")) return true; return false; }', 'success'=>'reloadGrid'));

// This button does not submit POST data

echo CHtml::ajaxSubmitButton('Do it', array('product/test'), 

		array( 	'data'=>'js:$(this).serialize()',



				'error'=>'function() {alert("Something went wrong.");}',

				'complete'=>'function(){$("#relation-dialog").dialog("open"); return false;}',

				'success'=>'function(data){$("#relation-dialog div.divForForm").html(data.div);}',



echo CHtml::endForm();


I have also tried a SubmitButton.

<?php echo CHtml::submitButton('Do it',

		array('id'=>'submit_button')); ?>

With some jquery:




And then the addRelation() function as described in the tutorial by zaccaria which as I said before works just fine in another script of mine.

What am I doing wrong?

Thanx in advance for any suggestion.

I think I have solved the problem.

First I replaced the CHtml::SubmitButton with a CHtml::Button.

2nd I added an onclick event: array(‘id’=>‘submit_button’, ‘onclick’=>‘addFunction();’)); to that CHtml::Button.

And 3rd I found out, that the ‘this’ in the code below does not refer to the input data of the form.

<?php echo CHtml::ajax(array(


    'data'=> 'js:$(this).serialize()',




So I changed one line to:

'data'=>array('ajaxData'=>'js:$(".checkbox_id :checked").serialize()',

I have added a css.class ‘checkbox_id’ to the CCheckBoxColumn to be able to omit the first checkbox.

And all of a sudden my POST variable was full of data :wink: