Well, of course is possible, but depends on your approach. ajaxSubmitButton is a wrapper for jQuery ajax, so you would do something like:
<?php
echo CHtml::ajaxSubmitButton('Save','your-url',array(
'type'=>'POST',
'dataType'=>'json',
'success'=>'js:function(data){
if(data.result==='success'){
// do something on success, like redirect
}else{
$('#some-container').html(data.msg);
}
}',
));
?>
//the controller action that handles the ajax request
public function actionBuh(){
if(isset($_POST['Buh'])){
$model=new Buh();
$model->attributes=$_POST['Buh'];
if(!$model->save())
exit(json_encode(array('result'=>'error','msg'=>CHtml::errorSummary($model))));
else
exit(json_encode(array('result'=>'success','msg'=>'Your data has been successfully saved')));
}else{
exit(json_encode(array('result'=>'error','msg'=>'No input data has been passed.')));
}
}
public function actionCreate() {
if (isset($_POST['Pagine'])) {
$model = new Pagine;
$model->attributes = $_POST['Pagine'];
if (!$model->save())
exit(json_encode(array('result' => 'error', 'msg' => CHtml::errorSummary($model))));
else
exit(json_encode(array('result' => 'success', 'msg' => 'Your data has been successfully saved')));
}else {
exit(json_encode(array('result' => 'error', 'msg' => 'No input data has been passed.')));
}
}
I think i understand why you get the error, you didn’t understand what i meant with the ajax create url, so modify the create action like so:
public function actionCreate() {
if(Yii::app()->request->isAjaxRequest){
if (isset($_POST['Pagine'])) {
$model = new Pagine;
$model->attributes = $_POST['Pagine'];
if (!$model->save())
exit(json_encode(array('result' => 'error', 'msg' => CHtml::errorSummary($model))));
else
exit(json_encode(array('result' => 'success', 'msg' => 'Your data has been successfully saved')));
}else {
exit(json_encode(array('result' => 'error', 'msg' => 'No input data has been passed.')));
}
}
// render the create page[this is an example, do it to match your case]
$model=new Pagine();
$this->render('create',array('model'=>$model));//this view will have the form in it
}
Can anyone tell me how to render an image in ajaxsubmitbutton. I have declared the type as image in htmloptions but it is not rendering. here is my code