Skip Navigation

[Resolved] Frontend child form, after submission, redirect to parent post

This support ticket is created 5 years, 3 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.

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/Hong_Kong (GMT+08:00)

This topic contains 2 replies, has 2 voices.

Last updated by Gavin 5 years, 3 months ago.

Assisted by: Luo Yang.

Author
Posts
#1314163

Tell us what you are trying to do?
When user visits an event, there'll be a link ( [cred_child_link_form] ) which takes them to a form where they can add additional information to that event. After successful submission, the user is redirected to the original parent event, where they can again find the [cred_child_link_form] link and again submit further information about the event (another date, another description, etc).

Is there any documentation that you are following?
--- https://toolset.com/documentation/programmer-reference/cred-api/#cred_success_redirect. I tested using the example in this doc, and this works....
add_filter('cred_success_redirect', 'custom_redirect',10,3);
function custom_redirect($url, $post_id, $form_data)
{
if ($form_data['id']==46)
return 'hidden link';
return $url;
}

--- https://toolset.com/documentation/post-relationships/selecting-parent-posts-using-forms-create-child-items/#creating-forms-when-a-parent-post-is-preselected - this is exactly what I want, and it works. I inserted the child post form into the parent post, and when clicked, it goes to the page identified as containing the child post form. When filled and submitted, the child post is successfully created.

--- https://toolset.com/forums/topic/redirecting-tot-parent-post-after-submission-of-a-child-cred-form/ - I've added this to my function.php, and also tried it using the Snippets plugin, but the child form page just refreshes. You can try it yourself to replicate the problem. Here's the code I used....
//added the child form id '46'
add_filter('cred_success_redirect_46', 'redirect_to_parent', 10, 3);
function redirect_to_parent($url, $post_id, $thisform) {
//added the parent post type slug 'event' to 'wpcf_belongs_slug_id'
$parent_id = get_post_meta( $post_id, '_wpcf_belongs_event_id', true);
return get_permalink( $parent_id );
}

What is the link to your site?
hidden link - this is just a test site.
--- click on any item, this takes you to the single event. There'll you'll find the 'Create new' link which takes you to the form. The URL is, e.g. /add-event-details/?parent_event_id=39. After successful submission, the page just refreshes and the URL is now /add-event-details/?cred_referrer_form_id=46. I want to redirect to the original parent post, where the 'Create new' link resides.

I have also set 'After visitors submit this form: > Go to a page... > Add Event' in the child form settings, as per the advice at https://toolset.com/documentation/programmer-reference/cred-api/#cred_success_redirect

Thanks.

#1314225

Hello,

The PHP codes you mentioned above is for old version of Toolset Types plugin, it is outdated.

In the latest version of Types plugin, with new post type relationship, I suggest get the parent post ID using $_POST variable, for example, change this line from:
$parent_id = get_post_meta( $post_id, '_wpcf_belongs_event_id', true);

To:
$parent_id = $_POST['@event-information_parent'];

Please replace "event-information" with the post type relationship slug between "Event" and "Additonal infromation"

#1314237

Thanks Luo - this now works perfectly. All the best. Gavin.