This is my code in view:
<?php
$form = $this->beginWidget('CActiveForm', array(
'id' => 'swim-subscribe-form',
'enableAjaxValidation' => true,
'action'=>"/mycontroller/myfunction"
));
?>
<?php
echo CHtml::ajaxSubmitButton('Save',array('/mycontroller/myfunction'),array(
'type'=>'POST',
'dataType'=>'post',
'success'=>'js:function(data){
}',
));
$this->endWidget();
?>
This is my controller:
public actionMyFunction(){
$model = new MyModel;
$this->performAjaxValidation($model);
if ($model->save()) {
$this->redirect('/another_controller');
}
}
protected function performAjaxValidation($model) {
if (isset($_POST['ajax']) && $_POST['ajax'] === 'swim-subscriber-form') {
echo CActiveForm::validate($model);
Yii::app()->end();
}
}
This code somehow, it always do a submit my url /mycontroller/myfunction
. It doesn't show on my console that I call the /mycontroller/myfunction
through ajax. Why ?
UPDATE This is what generated my ajaxSubmitButton:
<input name="yt0" value="Save" id="yt0" type="submit">
Is this ok ?