Skip Navigation

[Resolved] Repeatable Field Groups form

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

Problem: I would like to make the process of submitting repeatable field groups (RFGs) in Forms simpler. Since I cannot create RFGs in the same Form that manages a parent post, I would like to redirect back to the parent post after the User creates an RFG in Forms.

Solution: You can use the Forms redirection API to redirect to any custom post or page. In the Form settings, you must set up some redirection. It doesn't matter which page or post you choose in the Form settings, but you must choose something for redirection. Then add the following custom code in your child theme's functions.php file, or in a custom 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)
{
  $forms = array( 12345 );
  $rfg_slug = 'your-rfg-slug';
  if ( in_array( $form_data['id'], $forms ) ) {
    $parent_id = toolset_get_related_post( $post_id, $rfg_slug );
    return get_permalink($parent_id);
  }
  return $url;
}

Replace 12345 with the ID of the RFG form, and replace your-rfg-slug with the slug of your RFG. Then this code will automatically redirect to the single parent post after submitting the form.

Relevant Documentation:
https://toolset.com/documentation/programmer-reference/cred-api/#cred_success_redirect

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.

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 7 replies, has 2 voices.

Last updated by nabils 4 years, 7 months ago.

Assisted by: Christian Cox.

Author
Posts
#1567097

Tell us what you are trying to do?
Hi,
I have a post x that has Repeatable Field Groups called files. I want to know, can I add the Repeatable Field Groups form inside post x form so the user can add the files directly when creating the post?

#1567373

Hello, in the current system you cannot create or edit an RFG within the same Form that creates or edits its parent post. Those two processes require separate Forms. It is also not possible to edit multiple rows of an RFG in the same Form, each row must be edited independently. We are working to improve the usability of Forms with RFGs, so I hope this process will change soon. If you'd like to request this feature, feel free to submit your request here: https://toolset.com/home/contact-us/suggest-a-new-feature-for-toolset/
If more people request this feature, hopefully it will be added sooner.

#1568073

In this case is there a way to go back to previous page where add new repeatable filed group link and list of all repeatable files is. So, the user can see the list updated with new record.

#1568363

Yes, you can use Forms redirection API to redirect to any custom post or page. Let's assume the list of RFG is on the parent post. In the Form settings, you must set up some redirection. It doesn't matter which page or post you choose in the Form settings, but you must choose something for redirection. Then add the following custom code in your child theme's functions.php file, or in a custom 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)
{
  $forms = array( 12345 );
  $rfg_slug = 'your-rfg-slug';
  if ( in_array( $form_data['id'], $forms ) ) {
    $parent_id = toolset_get_related_post( $post_id, $rfg_slug );
    return get_permalink($parent_id);
  }
  return $url;
}

Replace 12345 with the ID of the RFG form, and replace your-rfg-slug with the slug of your RFG. Then this code will automatically redirect to the single parent post after submitting the form. If your list is somewhere else, please explain and I can offer a code update.

#1570605

I have added the code in function.php. I have also set the After visitors submit this form go to a specific post but still it is not working

 add_filter('cred_success_redirect', 'custom_redirect_rfg_editor',10,3);
function custom_redirect_rfg_editor($url, $post_id, $form_data)
{
  $forms = array( 2762 );
  $rfg_slug = 'rental_file';
  if ( in_array( $form_data['id'], $forms ) ) {
    $parent_id = toolset_get_related_post( $post_id, $rfg_slug );
    return get_permalink($parent_id);
  }
  return $url;
}
#1571391

Okay just to be clear, the file name is usually functions.php, with an "s". If this is not working I'll be glad to take a closer look. Please provide login credentials in the private reply fields here, and tell me where I can find this form on the front-end of your site. I will run a couple of tests and give you some feedback.

#1574963
Screen Shot 2020-04-05 at 6.14.49 PM.png

Sorry I was not clear about this, in wp-admin you must choose a post for the redirect. You have not selected an actual post yet, as you can see in this screenshot, it still says "select post". You must choose an actual post there. I set it to redirect to the "Dashboard" page for you, and I think it is working now. I submitted a new Rental File in this Rental post:
hidden link

After the Form was submitted, I was returned to the Rental post:
hidden link

Can you check and confirm it's working now?

#1575295

My issue is resolved now. Thank you!