Hey guys,
I’m having a strange problem since upgrading from Yii 1.1 to 1.1.2 or even the latest release 1.1.3.
Using the following code
<div class="form">
<?php if(isset($err)) { echo $err; } ?>
<?php echo CHtml::beginForm($this->createUrl('usersComments/ajaxCreate')); ?>
<p class="note">Fields with <span class="required">*</span> are required.</p>
<?php echo CHtml::errorSummary($model); ?>
<div class="row">
<?php echo CHtml::activeLabelEx($model,'comments_data'); ?>
<?php echo CHtml::activeTextArea($model,'comments_data',array('rows'=>6, 'cols'=>50)); ?>
<?php echo CHtml::error($model,'comments_data'); ?>
</div>
<div class="row buttons">
<label for='submit'></label>
<?php echo CHtml::ajaxSubmitButton('Comment',$this->createUrl('usersComments/ajaxCreate'),array('update'=>'#users-comments')); ?>
</div>
<?php echo CHtml::activeHiddenField($model,'comments_owner',array('value'=>$user->users_id)); ?>
<?php echo CHtml::endForm(); ?>
</div><!-- form -->
<div style='height:10px;'></div>
and controller;
//function to make comment ajax
public function actionAjaxCreate()
{
$model=new UsersComments;
if(Yii::app()->request->isAjaxRequest)
{
$model->attributes=$_POST['UsersComments'];
//make comment, load data
if($model->save())
{
//load data
$ph=Users::model()->findByPk($model->comments_owner);
$this->renderPartial('_ajax_comments',array('model'=>$ph),false,true);
}
else
{
$err="Don't forget to write a comment";
//load data
$ph=Users::model()->findByPk($model->comments_owner);
$this->renderPartial('_ajax_comments',array('model'=>$ph,'err'=>$err),false,true);
}
}
}
is executing a random amount of times.
If I use Yii 1.1 it’s fine, it only executes/submits once.
Problem only occurs if the form is rendered via an CHtml::ajaxLink call.
Is there a bug with 1.1.2 onwards that is causing Ajax to submit multiple times?
Cheers,
Snorcha