Delete entries and comments

ExpressionEngine 1.x, ExpressionEngine 2

Back to this add-on's main page
View Other Add-ons From Milo Creative


You must be logged in to post.

AJAX Example?



Thanks for this plugin, it’s already proving itself handy.

In the plugin docs you mention “You can also use AJAX to delete an entry ‘under the hood’ and fetch the plugin response to display as feedback to users.”

Would you mind giving and example of this?

Chief Alchemist
# 1
Chief Alchemist

Yes, where can I find an Ajax example. This is the missing link to a UI / UX I’m building.

Chief Alchemist
# 2
Chief Alchemist

Yes, where can I find an Ajax example. This is the missing link to a UI / UX I’m building.

Adam Smith
# 3
Adam Smith

I used this for a user portfolio site, where each entry has an image. Sort of like dribbble or behance.

First we have our delete template (portfolio/delete in my example), which has this code:

error_no_permissions="You're not allowed to delete this image" 
error_invalid_content="It seems that this image has been already deleted" 
message_success="An item has successfully been removed from your portfolio."

Then we have the portfolio/index template with our channel entries tag, and delete buttons below each entry.

<div class="delete-ajax" ></div>
ul id="portfolio-grid">
{exp:channel:entries channel="portfolio_images" }
img src="{portfolio_image_url}" />
{exp:delete:link id="{entry_id}" type="image" template="portfolio/delete" alert="true" title="{title}" class="item-delete"}

Then I wrote a jQuery script, which loads delete button’s URL in the background (in our hidden .delete-ajax div), and hides the image that is being deleted when an entry’s delete button is clicked:

$(document).ready(function() {
$('a.item-delete') .click (function() {
var link = $(this).attr('href')
item = $(this).parent('li')
'.delete-ajax').fadeIn().load(link, function() {

I’m not sure if this is the best way, but it works.

Hope it helps!

Chief Alchemist
# 4
Chief Alchemist

Hi Adam - Thanks.

My additions / thoughts…

1) I did set up a sandbox page and noticed that if I put the delete code in the same template that I’m rendering the list with, it looked as if the page did not refresh. Mind you, the page was pretty light weight so it’s hard to say what would happen if there were headed pngs, etc. Ultimately, I’m just trying to avoid a “blink” of a page refresh. I don’t get the fade effect but that might not be necessary anyway.

2) So you’re using load() but it doesn’t look like you’re catching a response anywhere. I read this quickly and it looks like the method does the dirty work, correct? In short, this isn’t an Ajax solution in the technical sense (no Ajax methods, no JSON response, etc.) but in the end it looks and acts like it (i.e., no page refresh), correct?

Given that it looks like this add-on is no longer being developed and it’s probably not supported either, as simple as it is, I have to ask…is there anything else I need to know that might prevent me from an evening of unexpected troubleshooting? ;)

Thanks again for your input. Hopefully you’ll have a moment to chime in on the above.


Adam Smith
# 5
Adam Smith

You’re right, I’m not looking for a response. All I was focussed on was deleting an image without a page refresh (which my method does).

Best of luck getting it to work on your end!

Chief Alchemist
# 6
Chief Alchemist

Thanks again Adam.

Actually, one more question, please.

Do I need to worry about this plug-in being spoofed into deleting other’s entries. By that I mean, if I’m passing the entry_id to delete via a segment, what’s to stop a use from trying to delete other entries just by changing that value and hitting return? Or is such authentication (if you will) built into this and/or EE.

Pardon me but I’m used to doing everything via the CP. I’m finally needing to learn SafeCracker. But the EE docs are pretty lite on the subject. Doin’ a Google doesn’t add much either.

Adam Smith
# 7
Adam Smith

Hey Mark,

I’m not the creator of this addon (just another user trying to figure it out), so I don’t know the answer to your question.

It shouldn’t be too hard to test that senario though.

Chief Alchemist
# 8
Chief Alchemist

Greeting Adam

Yup, got it. I know it’s not your baby. I just thought you might have run into this.

I looked at the code a couple weeks ago and I didn’t see anything about current user id = author id. But I didn’t think to look for that then either.

I’ll test, as suggested, and will try to report back. Worst case, I’ll come up with a delete category or status and just do a manual clean up from time to time. Safecracker has an only author can edit option, at least I think I notice that as a parm.

# 9

I tried to use this but it would delete the entry/comment in any case, even if the action is cancelled with the alert (obviously). How can I make it work so that if I cancel the action nothing happens?