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.
Hello,
For the post form adding child RFG instance, please try below codes:
add_filter('cred_success_redirect', 'custom_redirect',10,3);
function custom_redirect($url, $post_id, $form_data)
{
$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)){
$server_id = $_POST['@' . $arr[$form_data['id']] . '_parent'];
$url = get_permalink($parent_post);
}
return $url;
}
Hi Luo,
Hmm, doesn't seem to work.
The form that adds a RFG is on a page.
I do have the form set to redirect to the home page after submitting.
A successful submit redirects back to the same page with the original form on it.
The resulting URL shows: /page/?cred_referrer_form_id=282
Seems like it is redirecting, but only back to the submitting form, not the parent post.
Thank you so much for taking another look!
Please try to modify the PHP codes as below and test again:
add_filter('cred_success_redirect', 'custom_redirect',10,3);
function custom_redirect($url, $post_id, $form_data)
{
$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= $_POST['@' . $arr[$form_data['id']] . '_parent'];
$url = get_permalink($parent_post);
}
return $url;
}
It works fine, in my localhost
Hi Luo,
I'm sorry but I get the same result.
I will try to use a Layout instead of a page to hold the form.
Thanks for trying.
Kelly
To be clear I will restate here what I am trying to do...
I have a CPT parent and an RFG child.
I have a form for adding RFG to a CPT, and a form for editing the RFG.
Both forms are within layouts and are set to redirect to the home page.
I want the forms to redirect to the parent post after successful subit.
The code above works perfectly when editing an RFG but not when adding an RFG.
Here is my redirecting edit code (works great, redirects to parent post) :
add_filter('cred_success_redirect', 'custom_redirect',10,3);
function custom_redirect($url, $post_id, $form_data)
{
$markedit = array(
// edit marks
'215' => 'business-marks-group',
'211' => 'place-marks-group',
);
if (array_key_exists($form_data['id'], $markedit)){
$parent_post= $_POST['@' . $markedit[$form_data['id']] . '_parent'];
$url = get_permalink($parent_post);
}
return $url;
}
Here is my not redirecting add code (not redirecting to parent post):
add_filter('cred_success_redirect', 'custom_redirect',10,3);
function custom_redirect($url, $post_id, $form_data)
{
$markadd = array(
// add marks
'424' => 'business-marks-group',,
'213' => 'place-marks-group',
);
if (array_key_exists($form_data['id'], $markadd)){
$parent_post= $_POST['@' . $markadd[$form_data['id']] . '_parent'];
$url = get_permalink($parent_post);
}
return $url;
}
The RFG is added but redirects to the home page (as set in the form).
Wow, I hope you are able to understand my writing, I'm not a technical person.
Dear Luo, Thank you so much for your kind help, you guys are awesome!
Kelly
Since it is a custom codes problem, please provide a test site with the same problem, also point out:
- The problem page URL and form URL
- Where I can edit your custom PHP codes,
I need a live website to test and debug, thanks