Skip Navigation

[Resolved] redirect from RFG form successful submit

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

Problem:

I have a form for editing a CPT with a link to another form for editing a RFG.

When the RFG form is submitted I want to redirect back the CPT form.

Solution:

You can try with filter hook cred_success_redirect to redirect user to parent post,for example:

https://toolset.com/forums/topic/redirect-from-rfg-form-successful-submit/#post-1741441

Relevant Documentation:

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

This support ticket is created 4 years, 5 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 9 replies, has 2 voices.

Last updated by kellyR 4 years, 5 months ago.

Assisted by: Luo Yang.

Author
Posts
#1736415

Tell us what you are trying to do?
I have a form for editing a CPT with a link to another form for editing a RFG.
When the RFG form is submitted I want to redirect back the CPT form.
(After visitors submit this form:) There is no selector for this.
"Display the post" is grayed out, not available.

It seems like a much needed feature but nothing found.

Is there any documentation that you are following?
I have been searching but found nothing specifically for this.

#1737169

Hello,

You are right, there isn't such a builtin feature within Toolset Forms plugin, the RFG is based on one-to-many relationship, so you can try with filter hook cred_success_redirect to redirect user to parent post, see our document:
https://toolset.com/documentation/programmer-reference/cred-api/#cred_success_redirect

For example:

add_filter('cred_success_redirect', 'custom_redirect',10,3);
function custom_redirect($url, $post_id, $form_data)
{
    if ($form_data['id']==123)
        $parent_post = toolset_get_related_post($post_id, 'your-RFG-field-slug', 'parent');
        $parent_post_url = get_permalink($parent_post);
        return $parent_post_url ;
}

Please replace 123 with your Toolset form ID, and replace your-RFG-field-slug with the RFG slug.

#1737631

H Luo,
What about a code for multiple RFGs?
Please would you show a code for that?
Or would it be better to use separate codes for each?
Thank you so much for your quick solution!
K.

#1738229

As I mentioned above: the RFG is based on one-to-many relationship
So each item of RFG is also a post, one post form can handle only one post, you will need setup different post form for different RFG items, and setup different PHP codes for different post form(RFG).

#1739827

Hi Luo,
Is it possible to have an array to handle multiple form redirects?
The reason I ask is that I saw this discussion before when I was searching for an answer...
https://toolset.com/forums/topic/redirect-change-form-after-input-to-a-spesifique-archive-content-template/
Thanks much for your help!

#1741441

Yes, it is possible, for example:

add_filter('cred_success_redirect', 'custom_redirect',10,3);
function custom_redirect($url, $post_id, $form_data)
{
	$res = $url;
	$arr = array(
		'123' => 'your-RFG-field-slug', //replace 123 with form's ID, replace your-RFG-field-slug with RFG field slug
		'456' => 'your-RFG-field-slug2', // add more form's IDs and RFG field slugs
	);
    if (array_key_exists($form_data['id'], $arr)){
        $parent_post = toolset_get_related_post($post_id, $arr[$form_data['id']], 'parent');
        $res = get_permalink($parent_post);
	}
	return $res;
}

More help:
hidden link

#1742423

The first (single) code you gave works perfectly, but the new code above only redirects to the home page. The code below is what I have based on last code. Sorry but I do not know PHP.

/* Redirects Map Marker create/edit to Parent post. ^/
add_filter('cred_success_redirect', 'custom_redirect',10,3);
function custom_redirect($url, $post_id, $form_data)
{
$res = $url;
$arr = array(
'284' => 'my-marks-group',
'283' => 'place-marks-group',
'273' => 'business-marks-group',
);
if (array_key_exists($form_data['id'], $arr)){
$parent_post = toolset_get_related_post($post_id, $arr[$form_data['id']], 'parent');
$res = get_permalink($parent_post);
}
return $res;
}

#1742485

Correction > Your code works perfectly!
Sorry for my confusion.

#1742487

My issue is resolved now. Thank you!

#1744713

Hi Luo,
Would there be another solution for 'ADDING' an RFG?
A Page contains an RFG Form for adding additional RFG instances.
Is it possible to redirect to the Parent post after submitting the RFG Form?
Like what you showed me above, but for Adding not Editing?
Thank you!
Hope you are having a nice day.

New threads created by Luo Yang and linked to this one are listed below:

https://toolset.com/forums/topic/would-there-be-another-solution-for-adding-an-rfg/