I am using this below code for confirmation before deleting an item in my index page.
But i want my confirm box to be a beautiful one. Can u tell me what i have to do???
I don’t understand how to integrate jquery plugin here… Please if u have time then help me…
my controller name is LatestnewsController
my model name is latestnews
my method name is actionDelete
echo CHtml::link(‘Delete’, “#”, array(“submit”=>array(“delete”,“id”=>"$latestnews->id" ),“confirm”=>“Are you sure?”));
abennouna
(Abennouna)
March 19, 2012, 6:22am
2
I am using this below code for confirmation before deleting an item in my index page.
But i want my confirm box to be a beautiful one. Can u tell me what i have to do???
I don’t understand how to integrate jquery plugin here… Please if u have time then help me…
my controller name is LatestnewsController
my model name is latestnews
my method name is actionDelete
echo CHtml::link(‘Delete’, “#”, array(“submit”=>array(“delete”,“id”=>"$latestnews->id" ),“confirm”=>“Are you sure?”));
You may want to use jQuery Impromptu or some other plugin
I have downloaded the plugin… and in my project’s …/…/layout/main.php i have added the script path…
but i don’t know how to implement it?
abennouna
(Abennouna)
March 19, 2012, 3:12pm
4
If you see the source code generated by Yii for your first code, you’ll find something like this
$('body').on('click', '#yt0', function() {
if(confirm('Are you sure?')) {
jQuery.yii.submitForm(this,'someController/delete/5',{});
return false;
} else
return false;
});
You should in fact change your PHP code to render just the link with some HTML class (because an id would mean there’s just one link of such on the page).
So your code should change from
echo CHtml::link('Delete', "#", array("submit"=>array("delete","id"=>"$latestnews->id" ), "confirm"=>"Are you sure?"));
to
echo CHtml::link('Delete', array("delete","id"=>"$latestnews->id") , array('class'=>'someClass'));?>
and you add the needed JavaScript code for the class someClass like the one generated by Yii:
$('body').on('click', '.someClass', function(e){
e.preventDefault();
var txt = 'Are you sure?<input type=\"hidden\" name=\"href\" value=\"'+ $(this).attr('href') +'\" />';
$.prompt(txt, {//look in the plugin doc and demos for more options
buttons: {Delete:true, Cancel:false},
callback: function(e,v,m,f) {
if(v){
jQuery.yii.submitForm(this, f.href, {});
return false;
} else
return false;
}
});
});
abennouna
(Abennouna)
March 20, 2012, 6:14am
6
Well it was an example.
What’s the JavaScript code generated by Yii for your first confirm CHtml link?
That’s the code you should put in the snippet, maybe with some adaptation.
gnongkynrih
(Gordon Nongkynrih)
March 21, 2012, 3:18pm
7
Thanks for your reply…
but its not deleting…
You may need to include yii core script for using jQuery.yii.submitForm
you can do this by including the following Yii::app()->clientScript->registerCoreScript(‘jquery.yii’);
you can do something like this:
CHtml::link(
'Delete',
'#',
array('submit'=>array('wsrecruiteducation/delete','id'=>$model->EducID),
'params'=>('returnUrl'=>'controller/action...'), 'confirm' => 'Are you sure?')
);
The returnUrl will be a post item sent with the request, make sure you make something like this in a controller with delete action:
…
if(!isset($_GET[‘ajax’]))
$this->redirect(isset($_POST['returnUrl']) ? array($_POST['returnUrl']) : array('admin'));
…