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.
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.
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.
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).
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!
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
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;
}
Correction > Your code works perfectly!
Sorry for my confusion.
My issue is resolved now. Thank you!
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.