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">
<?php echo CHtml::link('Save Comment', '#', array('onclick' => 'saveChild(); return false;')); ?>
</div>[/b]
the jquery function code is the following
[b]function saveChild()
{
var data=$(’#comment-form’).serialize();
$.ajax({
type: 'POST',
url: '<?php echo Yii::app()->createAbsoluteUrl('comment/Ajax'); ?>',
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