Skip Navigation

[Resolved] Workflow for Frontend Editing of Repeatable Field Groups and redirect to parent post

This thread is resolved. Here is a description of the problem and solution.

Problem: I would like to use a Form to edit a repeatable field group (RFG). After the Form is submitted, I would like to redirect to the parent post.

Solution: Use this custom code snippet to redirect to the parent post. Be sure to set your Form to redirect to some custom page.

add_filter('cred_success_redirect', 'custom_redirect_rfg_editor',10,3);
function custom_redirect_rfg_editor($url, $post_id, $form_data)
{
  if ($form_data['id']==12345)
    $writer = toolset_get_related_post( $post_id, 'your-rfg-slug' );
    return get_permalink($writer);
  return $url;
}

Replace 12345 with the numeric ID of this Form, and replace your-rfg-slug with your actual RFG slug.

Relevant Documentation:
https://toolset.com/documentation/programmer-reference/cred-api/#cred_success_redirect
https://toolset.com/documentation/customizing-sites-using-php/post-relationships-api/#toolset_get_related_post

This support ticket is created 6 years 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.

No supporters are available to work today on Toolset forum. Feel free to create tickets and we will handle it as soon as we are online. Thank you for your understanding.

Sun Mon Tue Wed Thu Fri Sat
8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 - -
13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 - -

Supporter timezone: America/New_York (GMT-04:00)

This topic contains 2 replies, has 2 voices.

Last updated by KentS9937 6 years ago.

Assisted by: Christian Cox.

Author
Posts
#1147321

I have a post type "Job Application" which has a repeatable field group "Previous Employer". I have successfully created a form to add new posts for Previous Employer and I'm able to display those on the template for the Job Application. I am struggling to follow the instructions for how to allow users to edit the Previous Employer on the front end.

I'm following the instructions from this page :
https://toolset.com/documentation/getting-started-with-toolset/creating-and-displaying-repeatable-field-groups/front-end-forms-for-repeatable-field-groups/#forms-for-editing-values-of-existing-repeatable-field-groups

I'm stuck on the instructions at the end where it says "You can now add your new View to a post (or a template) that has a repeatable field group whose values you want to edit." If I add this view to my Job Application template then it's displaying the Previous Employers and displaying a form to edit the Previous Employer. I'm sure I'm not understanding the directions correctly.

I have tried adding an edit link to the Previous Employer view which takes the user to a form to edit the Previous Employer. But I don't find a way to direct them back to the Job Application after they save their changes. The option to "Display the Post" after submitting the form is greyed out.

Can you help me better understand how I should get a user from the Job Application template to editing a Previous Employer and back to the original Job Application?

#1147434

Hi, redirecting automatically to the parent post requires a small custom code snippet. First, configure your Form to redirect to some custom Page. It doesn't matter which Page you choose, but you must choose something. Our code will override that selection. Then add the following code to your child theme's functions.php file, or create a new code snippet in Toolset > Settings > Custom code:

add_filter('cred_success_redirect', 'custom_redirect_rfg_editor',10,3);
function custom_redirect_rfg_editor($url, $post_id, $form_data)
{
  if ($form_data['id']==12345)
    $writer = toolset_get_related_post( $post_id, 'your-rfg-slug' );
    return get_permalink($writer);
  return $url;
}

Replace 12345 with the numeric ID of this repeatable field group (RFG) edit Form, and replace 'your-rfg-slug' with the slug of this RFG. More information about the APIs here:
https://toolset.com/documentation/programmer-reference/cred-api/#cred_success_redirect
https://toolset.com/documentation/customizing-sites-using-php/post-relationships-api/#toolset_get_related_post

#1147449

Thanks for your help Christian! Worked perfectly.
My issue is resolved now. Thank you!