Welcome Guest, Not a member yet? Register   Sign In
How Confirm before delete?
#1

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


thanks all Smile
#2

[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.
#3

[eluser]Asinox[/eluser]
mm ok thanks

i was thinking that CI hav something for this

thanks
#4

[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;
    }
});
#5

[eluser]Asinox[/eluser]
Thanks Lone Smile
#6

[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.
#7

[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...
#8

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

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

[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.
#10

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




Theme © iAndrew 2016 - Forum software by © MyBB