Forum Moderators: open

Message Too Old, No Replies

Confirmation Alert

         

almo136

1:06 am on Jun 16, 2009 (gmt 0)

10+ Year Member



Hi

I have this link which deletes a blog post:

[mysite.com...]

Does anyone know what I would add to this so a confirmation alert box pops up allowing the user to cancel or proceed with the action?

Thanks.

PokeTech

1:13 am on Jun 16, 2009 (gmt 0)

10+ Year Member



<script type="text/javascript">

function Confirm() {
var answer = confirm("Are you sure you want to delete this post?");
if (answer) {
window.location='http://mysite.com/wordpress/wp-admin/post.php?action=delete&post=86&_wpnonce=a4dbc76dc9';
}
}
</script>

<a href="javascript:Confirm();">Delete Post</a>

Try that.

almo136

2:05 am on Jun 16, 2009 (gmt 0)

10+ Year Member



Didn't work. Just realised that I didn't explain the problem correctly though.

The link is actually created using php. This is the code which creates the link:

<?php if (current_user_can('edit_post', $post->ID)) echo "<a href='" . wp_nonce_url("/wordpress/wp-admin/post.php?action=delete&amp;post=$id", 'delete-post_' . $post->ID) . "'>Delete post</a>" ?>

Thanks.

PokeTech

3:21 am on Jun 16, 2009 (gmt 0)

10+ Year Member



change this:

function Confirm(goto) {
var answer = confirm("Are you sure you want to delete this post?");
if (answer) {
window.location= goto;
}
}

<?php if (current_user_can('edit_post', $post->ID)) echo "<a href='javascript:Confirm('" . wp_nonce_url("/wordpress/wp-admin/post.php?action=delete&amp;post=$id", 'delete-post_' . $post->ID) . "')'>Delete post</a>" ?>

Try that. I'm not 100% sure if it will work though.

Fotiman

1:39 pm on Jun 16, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Since your link already has the location that you want to go to, all you need to do is have an onclick handler that returns true of false (true means follow the link, false means don't). So:

<?php if (current_user_can('edit_post', $post->ID)) echo "<a href='" . wp_nonce_url("/wordpress/wp-admin/post.php?action=delete&amp;post=$id", 'delete-post_' . $post->ID) . "' onclick='return confirm(\"Are you sure you want to delete this post?\")'>Delete post</a>" ?>

almo136

5:53 pm on Jun 17, 2009 (gmt 0)

10+ Year Member



thanks!