Yii Framework Forum: Please Help me regarding confirm box - Yii Framework Forum

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

Please Help me regarding confirm box

#1 User is offline   Aashis 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 19
  • Joined: 18-March 12

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?"));
0

#2 User is offline   bennouna 

  • Master Member
  • PipPipPipPip
  • Yii
  • Group: Members
  • Posts: 1,166
  • Joined: 05-January 12
  • Location:Morocco

Posted 19 March 2012 - 01:22 AM

View PostAashis, 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?"));


You may want to use jQuery Impromptu or some other plugin
0

#3 User is offline   Aashis 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 19
  • Joined: 18-March 12

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?
0

#4 User is offline   bennouna 

  • Master Member
  • PipPipPipPip
  • Yii
  • Group: Members
  • Posts: 1,166
  • Joined: 05-January 12
  • Location:Morocco

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

$('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

0

#5 User is offline   Aashis 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 19
  • Joined: 18-March 12

Posted 19 March 2012 - 09:46 PM

Thanks for your reply....
but its not deleting...
0

#6 User is offline   bennouna 

  • Master Member
  • PipPipPipPip
  • Yii
  • Group: Members
  • Posts: 1,166
  • Joined: 05-January 12
  • Location:Morocco

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.
0

#7 User is offline   Gordon Nongkynrih 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 3
  • Joined: 14-March 12

Posted 21 March 2012 - 10:18 AM

View PostAashis, on 19 March 2012 - 09:46 PM, said:

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');
0

#8 User is offline   rajesh chaurasia 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 42
  • Joined: 12-January 13
  • Location:Mohali

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'));
...
0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users