Submit Child Form With Ajax

Hello,

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;





&lt;/div&gt;[/b]

the jquery function code is the following

[b]function saveChild()

{

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

$.ajax({

type: 'POST',


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


data:data,


success:function(data){


            alert('Data Saved'); 


          },


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


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


     alert(data);


},

dataType:‘html’

});

[/b]

(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?