I have a form and consists of 5 submit buttons (save,add,delete,radiobutton,etc) for all that I wanna make to
ajaxsubmitbutton
and access through ajax.
As I have
ajaxsubmitbuttons
shown below
echo CHtml::ajaxSubmitButton(
'Save', //the label
CController::createUrl('healthInformation/saveData'), //the url = index if empty (or set to another controllerAction)
array('update'=>'#healthData',), // the ajax-options: display the response inside this div
array('class'=>'adm-myButton','title'=>'Save','name'=>'save') //your htmlOptions
);
echo CHtml::ajaxSubmitButton(
'add', //the label
CController::createUrl('healthInformation/saveData'), //the url = index if empty (or set to another controllerAction)
array('update'=>'#healthData',), // the ajax-options: display the response inside this div
array('class'=>'adm-myButton','title'=>'Save','name'=>'add') //your htmlOptions
);
echo CHtml::ajaxSubmitButton(
'delete', //the label
CController::createUrl('healthInformation/saveData'), //the url = index if empty (or set to another controllerAction)
array('update'=>'#healthData',), // the ajax-options: display the response inside this div
array('class'=>'adm-myButton','title'=>'Save','name'=>'delete') //your htmlOptions
);
and my question is that can i access
actionsaveData()
by all above
ajaxsubmitbuttons
using their name as below
public function actionSaveData()
{
if(isset($_POST['save']))
{
}
if(isset($_POST['add']))
{
}
if(isset($_POST['delete']))
{
}
$this->renderPartial('');
}
Is it possible or else have to use different actions for all
You could add data in the ajax option and submit an button name.
Like ‘data’=>“button:add”
And you can check this in actionSaveData like you almost got right now.
Not tested, but this should be possible:
echo CHtml::ajaxSubmitButton(
'add', //the label
CController::createUrl('healthInformation/saveData'), //the url = index if empty (or set to another controllerAction)
array('update'=>'#healthData','data'=>"button:add"), // the ajax-options: display the response inside this div
array('class'=>'adm-myButton','title'=>'Save','name'=>'add') //your htmlOptions
);