I am using CJuidialog widget to wrap a view file, and I don’t want the default ‘save’ button because I would like to use a javascript to make an ajax call to the server for data validation, then save it. I tried below:
<?php
if($model->isNewRecord)
echo CHtml::submitButton('Create');
else
echo '<button onClick="javascript: _updatedata('.$model->id.');">Save</button>';
?>
when the save button is clicked. it still will go to the actionUpdate to save the form data, however I have created an action to just save my data.
function updatedata(id)
{
var url = '<?php echo Yii::app()->request->baseUrl ?>' + '/index.php?r=user/profileupdate&id='+id;
......
$.ajax({
url: url,
type: 'POST',
dataType: "html",
data:
{
...
},
success: function(data, textStatus, XMLHttpRequest) {
if (data != null && data == "success")
{
//$('#xccdfgrid').trigger('reloadGrid');
$('#userprofile').dialog('close');
}
else
alert(data);
},
......
If you got your question correct then what you are saying that instead of default button you need something that you can perform Ajax Things rite? if yes then you need to have
Ajax Submit Button. Yii gives you liberty to use ajax more easily then you are trying to do. Please see CJuiDialog and AjaxSubmitButton