Submit Child Form With Ajax


I have a problem when submitting my comment via Ajax. I got an integrity error because the post_id field (the comment is related to a post) is empty.

I’d like to automatically fill the field and set the value before submitting the form.

My form has a link button that calls a jquery function.

[b]<div class="row buttons">

	&lt;?php echo CHtml::link('Save Comment', '#', array('onclick' =&gt; 'saveChild(); return false;')); ?&gt;


the jquery function code is the following

[b]function saveChild()


var data=$(’#comment-form’).serialize();


type: 'POST',

url: '&lt;?php echo Yii::app()-&gt;createAbsoluteUrl('comment/Ajax'); ?&gt;',



            alert('Data Saved'); 


error: function(data) { // if error occured

     alert('Error occured.please try again');






(I tried to use AjaxSubmitButton but it displays a second comment form and I gave up because I cannot find help on this.)

How can I use the beforesend and is it the best solution?

Thank you in advance for your help

Need more info.

Why post_id is empty? do you have a form field with post_id value? or you want to get a value from parent record?