Skip Navigation

[Resolved] Redirect Form Submission to WordPress Page with Form Parameters in URL

This support ticket is created 5 years, 8 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.

No supporters are available to work today on Toolset forum. Feel free to create tickets and we will handle it as soon as we are online. Thank you for your understanding.

Sun Mon Tue Wed Thu Fri Sat
8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 - -
13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 - -

Supporter timezone: America/New_York (GMT-04:00)

This topic contains 3 replies, has 2 voices.

Last updated by Christian Cox 5 years, 7 months ago.

Assisted by: Christian Cox.

Author
Posts
#1219191

Tell us what you are trying to do?
On form submit, I want to redirect to a URL with parameters that were collected from the form. The second page has a secondary opt-in, and I want to prefill the values from the first form.

However, that's not an option in the "After visitors submit this form:" settings.

Is there a way to achieve this?

#1219285

Hi, the best way to redirect to a custom URL with params is to use the cred_success_redirect API: https://toolset.com/documentation/programmer-reference/cred-api/#cred_success_redirect
In the form settings, you must choose some page to redirect to. It doesn't matter which page you choose, our code will override that.

Let's say your first Form (ID 123) creates a post with a custom field "phone" and you want to redirect to a different page with the phone value in a URL parameter.

add_filter('cred_success_redirect', 'custom_redirect',10,3);
function custom_redirect($url, $post_id, $form_data)
{
    if ($form_data['id']==123) {
      $phone = get_post_meta($post_id, 'wpcf-phone', true);  
      return '<em><u>hidden link</u></em>' . $phone;
    }
    return $url;
}
#1219339

Can you send more than one parameter this way?

#1220042

Yes, you can send multiple params this way. After using the "?" operator to separate the first param from the rest of the URL, use the "&" operator to separate the params:

add_filter('cred_success_redirect', 'custom_redirect',10,3);
function custom_redirect($url, $post_id, $form_data)
{
    if ($form_data['id']==123) {
      $phone = get_post_meta($post_id, 'wpcf-phone', true);  
      $email = get_post_meta($post_id, 'wpcf-email', true);
      return '<em><u>hidden link</u></em>' . $phone . "&email=" . $email;
    }
    return $url;
}