Skip Navigation

[Closed] Would there be another solution for 'ADDING' an RFG?

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

Last updated by Luo Yang 4 years, 3 months ago.

Assisted by: Luo Yang.

Author
Posts
#1745137

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.

#1745139

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;
}
#1745619

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!

#1745983

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

#1758245

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

#1758403

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

#1758607

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

The topic ‘[Closed] Would there be another solution for 'ADDING' an RFG?’ is closed to new replies.