Skip Navigation

[Resolved] What's the proper way to add a delete link inside a form?

This support ticket is created 4 years, 7 months ago. There's a good chance that you are reading advice that it now obsolete.

This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.

Our next available supporter will start replying to tickets in about 0.96 hours from now. Thank you for your understanding.

Sun Mon Tue Wed Thu Fri Sat
- 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 -
- 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 -

Supporter timezone: Asia/Karachi (GMT+05:00)

This topic contains 8 replies, has 2 voices.

Last updated by donC-3 4 years, 7 months ago.

Assisted by: Waqar.

Author
Posts
#1597651

I want in the edit for page a user to be able to delete their post. I went into the advanced editor and added this at the bottom (showing the closing form so you know location)

[/credform]
[cred_delete_post_link action="trash" text="Delete %TITLE%" message_after="Post deleted." class="tt_delete_post" message="Are you sure you want to delete this post?" message_show="1"]

When I click it, it says "deleting..." and stays there. It does delete the post but doesn't do anything else. I also want to have it redirect to their custom profile page after deleting but that doesn't work (but may be because of the deleting... issue. Here's the code I have in that function (pulled from https://toolset.com/forums/topic/dynamic-redirect-for-cred_delete_post_link/ for the idea)

What am I missing?

Here's my existing function.php code:

add_filter("cred_redirect_after_delete_action", "tt_delete_post");
function tt_delete_post($redurl, $post_id) {
$user = wp_get_current_user();
$name = get_user_meta( $user->ID, 'user_login', true);
return "/userprofile/XXX/"; //hard coded for testing.
}

Thanks in advance

#1598471

Hi,

Thank you for contacting us and I'd be happy to assist.

The "cred_delete_post_link" shortcode expects the ID of the post to be deleted through "post" attribute, and if it is not provided it uses the current post in the loop if it is inside a view or a content template:
https://toolset.com/documentation/user-guides/front-end-forms/cred-shortcodes/#cred_delete_post_link

When used inside a form the current post's ID becomes complicated and would depend on how this edit form is being used. Is there any special reason that this delete link needs to be inside the edit form?

If you could share temporary admin login details, along with a link to a page with this form, I'll be in a better position to guide you with the next steps accordingly.

Note: Your next reply will be private and please make a complete backup copy, before sharing the access details.

regards,
Waqar

#1598481

Not sure you need to dig yet. i created it just outside the cred form tag but in the form page. I can certainly work on how it should be done but wasn't sure what the correct way is. Should I put it on another page (could add to the view page without a problem)? Or anything else I need to do different? Redirect I was putting in simply because once you delete that page won't exist anymore. I removed the delete off the page for now so if you can let me know what you recommend doing I can try that first.

#1598793

Thanks for writing back.

During some tests on my own website, I was able to reproduce this issue, where the "redirect" attribute or "cred_redirect_after_delete_action" doesn't seem to work, even though the post is deleted.
( ref: https://toolset.com/documentation/user-guides/front-end-forms/cred-shortcodes/#cred_delete_post_link )

I've shared these findings with the concerned team for further review and will keep you updated on the progress through this ticket.

Meanwhile, there is a different shortcode "cred-delete-post" in which the "onsuccess" attribute can be used to redirect to a certain page/post, if it's ID is known.

For example, to redirect to page/post with ID "123" after deletion:


[cred-delete-post action='trash' onsuccess='123']Delete %TITLE%[/cred-delete-post]

You can create a custom shortcode that can return the ID of the current user's profile page and then pass it through the "onsuccess" attribute.

I hope this helps! Please let us know if you need any further assistance.

#1599271

Thanks a lot. Definitely let me know what you find out. I'll try the other option for now. I need to do some work to get the users profile page but should be doable.

#1599437

You're very welcome and I'll keep you updated.

#1600111

When you can, how do you get it to use the shortcode? I created one and put in the delete post as:

[cred-delete-post action='trash' onsuccess='[get_postprofileid]' message='Are you sure you want to delete this slab?']Delete %TITLE%[/cred-delete-post]

But the link gets mangled and the shortcode value doesn't return there. But when I use the shortcode before it (to just output on the page) it does output the proper post id.

#1602103

Please add "get_postprofileid" in the "Third-party shortcode arguments" section, at WP Admin -> Toolset -> Settings -> Front-end Content and then try it again.

This step is needed whenever we need to use custom or third-party shortcode as Views shortcode argument.

Note: This "cred-delete-post" shortcode doesn't support the "message" attribute, so it will have no effect.

#1602105

I still have one issue but think that's on my end. It operated fine. Thanks again.