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?
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;
}
Can you send more than one parameter this way?
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;
}