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