Skip Navigation

[Resolved] Pass parameter of CRED fields to another form via URL

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

Problem:
Pass parameter of CRED fields to another form via URL

Solution:
You can pass the URL params to another form using the Tooslet form hook: cred_success_redirect

You can find proposed solution in this case with the following reply:
https://toolset.com/forums/topic/pass-parameter-of-cred-fields-to-another-form-via-url/#post-2044569

Relevant Documentation:
=> https://toolset.com/documentation/programmer-reference/cred-api/#cred_success_redirect

This support ticket is created 3 years, 7 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
- 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 10: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/Kolkata (GMT+05:30)

This topic contains 3 replies, has 2 voices.

Last updated by marcialB 3 years, 7 months ago.

Assisted by: Minesh.

Author
Posts
#2043809

Hi there

I'm following this solution here https://toolset.com/forums/topic/passing-parameters-and-values-in-cred-form-submit/#post-1264923 to pass the field values of a CRED form in the URL for another form (not toolset) to automatically populate some of the fields there.

add_filter('cred_success_redirect', 'custom_redirect',10,3);
function custom_redirect($url, $post_id, $form_data){
    if ($form_data['id']==5092)
        return 'xyz.com/form/?vn=first_name&nn=last_name&st=user_strasse&pl=user_plz&or=user_ort&em=user_email&ug=user_email';
    return $url;
}

The parameters work fine, the only issue is that instead of the content of the field, only their names appear in the URL. I understand that the current code isn't made for that. I assume in the thread linked above they fixed that issue, but I'm not able to follow that. Can you give me a hint on how I can get the values of my seven custom fields in to the URL?

In case it's relevant: this is a user form (to create users).

Thanks a lot for your help!

#2044157

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

Hello. Thank you for contacting the Toolset support.

Can you please show me where exactly you added the Toolset form and share the admin access details so I can review your custom fields and the share the solution.

*** Please make a FULL BACKUP of your database and website.***
I would also eventually need to request temporary access (WP-Admin) to your site. Preferably to a test site where the problem has been replicated if possible in order to be of better help and check if some configurations might need to be changed.

I have set the next reply to private which means only you and I have access to it.

#2044569

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

Can you please test now: hidden link

I've added the following code to "Custom Code" section offered by Toolsest:
=> hidden link

add_filter('cred_success_redirect', 'func_custom_redirect',30,3);
function func_custom_redirect($url, $post_id, $form_data){
    if ($form_data['id']==5092){
      $user_id = $post_id;
      $user_info = get_userdata($user_id);
       $first_name = $user_info->first_name;
       $last_name = $user_info->last_name;
      
       $user_strasse = get_user_meta($user_id,'wpcf-user_strasse',true);
       $user_plz = get_user_meta($user_id,'wpcf-user_plz',true);
       $user_ort = get_user_meta($user_id,'wpcf-user_ort',true);
       $user_email = $user_info->user_email;
      
      	return '<em><u>hidden link</u></em>'.$first_name.'&nn= '.$last_name.'&st='.$user_strasse.'&pl='.$user_plz.'&or='.$user_ort.'&em='.$user_email.'&ug='.$user_email;
    }
    return $url;
}

I can see all field values are populated with its correct values.

#2044647

Hi Minesh
Thank you very much for the help! It works perfectly.
Have a nice day!
Best,
Marcial