Page 1 of 1
Please Help me regarding confirm box
#1
Posted 18 March 2012 - 10:03 PM
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?"));
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?"));
#2
Posted 19 March 2012 - 01:22 AM
Aashis, on 18 March 2012 - 10:03 PM, said:
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?"));
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
#3
Posted 19 March 2012 - 08:01 AM
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?
but i don't know how to implement it?
#4
Posted 19 March 2012 - 10:12 AM
If you see the source code generated by Yii for your first code, you'll find something like this
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
to
and you add the needed JavaScript code for the class someClass like the one generated by Yii:
$('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; } }); });
This post has been edited by tellibus: 19 March 2012 - 10:13 AM
#6
Posted 20 March 2012 - 01:14 AM
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.
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.
#8
Posted 04 June 2013 - 04:32 AM
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'));
...
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'));
...
Share this topic:
Page 1 of 1