CodeIgniter Forums
How Confirm before delete? - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23)
+--- Thread: How Confirm before delete? (/showthread.php?tid=9810)

Pages: 1 2


How Confirm before delete? - El Forum - 07-09-2008

[eluser]Asinox[/eluser]
Hi everyone.... please, how ill confirm before delete from the data base?


thanks all Smile


How Confirm before delete? - El Forum - 07-09-2008

[eluser]AgentPhoenix[/eluser]
Easiest thing to do is probably use Javascript's window.prompt function. If you hit OK, it'll continue with the operation, otherwise, it'll stop it.


How Confirm before delete? - El Forum - 07-09-2008

[eluser]Asinox[/eluser]
mm ok thanks

i was thinking that CI hav something for this

thanks


How Confirm before delete? - El Forum - 07-09-2008

[eluser]Lone[/eluser]
The best way I have found to do this is using jQuery with the following code:

HTML
Code:
<a href="delete_url" class="confirmClick" title="Delete this file">Delete</a>

Javascript (jQuery)
Code:
$(".confirmClick").click( function() {
    if ($(this).attr('title')) {
        var question = 'Are you sure you want to ' + $(this).attr('title').toLowerCase() + '?';
    } else {
        var question = 'Are you sure you want to do this action?';
    }
    if ( confirm( question ) ) {
        [removed].href = this.src;
    } else {
        return false;
    }
});



How Confirm before delete? - El Forum - 07-09-2008

[eluser]Asinox[/eluser]
Thanks Lone Smile


How Confirm before delete? - El Forum - 07-09-2008

[eluser]xwero[/eluser]
A way to do it without javascript requires reloading the page.

Most of the times you need an identifier for the delete url so if you don't add the identifier your create a buffer. On reload you add the identifier to the url and then the deletion will happen.

An alternative is to add an ask url and if that is clicked the delete url will show. The advantage of this method is that you can add the identifier which makes it possible to single out a delete link. The first method adds all the identifiers to the delete urls.

From the javascript side the first method is better if the key is shown somewhere else on the page, for instance as a edit url indentifier. The second method requires (semi-)hardcodeing the delete url in javascript.


How Confirm before delete? - El Forum - 07-10-2008

[eluser]Bramme[/eluser]
I just use
Code:
&lt;input type="submit" name="del" value="confirm('are you sure you wish to delete?';")&gt;
This would work on a link too offcourse...

And if I have multiple confirms on a page, I just use functions...


How Confirm before delete? - El Forum - 05-06-2009

[eluser]CI fan[/eluser]
You can try this method: :question:

Code:
//JAVASCRIPT
function confirmMsg(delUrl,msg) {
  if (confirm(msg))
  {
    document.location = delUrl;
  }
}



How Confirm before delete? - El Forum - 05-06-2009

[eluser]slowgary[/eluser]
I agree that JavaScript is the way to go. Also, in some cases where the data set being deleted is smaller, it's better not to confirm, but to offer an undo. This saves the user from having to click another button to confirm, plus gives them an option to change their mind afterward.


How Confirm before delete? - El Forum - 05-07-2009

[eluser]Evil Wizard[/eluser]
I would not do a delete action via..
Code:
...
document.location(...

this means that bots trawling the site can trigger unwanted deletions which are better handled by posted methods, but using JavaScript to confirm the action to carry out then on the server/controller side have a hidden field to check that the form was in fact posted.