In my form, I have given a confirmation message before saving.
CHtml::submitButton('Save', array('confirm'=>'Are you sure you want to save?'));
But the message box appears two times... What is wrong ?
Here is the form where you can got the answer of your thing... this is one way of doing it...!!!
<?php $form=$this->beginWidget('CActiveForm', array(
'id'=>'customer-form-guest',
'enableClientValidation'=>true,
'clientOptions'=>array(
'validateOnSubmit'=>true,
'afterValidate' => 'js:function(form, data, hasError) {
if(hasError) {
alert("There are errors in form inputs please resolve it.");
}
else
{
var r = confirm("Are you sure y7ou want to do this ..?");
if(r == true)
{
return true;
}
else
{
return false;
}
}
}' ),
'htmlOptions'=>array('role'=>"form")));
<?php echo CHtml::submitButton($model->isNewRecord ? 'Create' : 'Save',
array('confirm'=> 'Are you sure?')); ?>
When Click on Save then Same Page render than Controller generate view that time also who messege that's an issue. You have to pass some value in URL and then When view load that time just write condition for that does't show twice.