Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
WPForms conditional form redirects
<?php
/**
* WPForms custom redirect
*
* @param string $url URL form will redirect to
* @param int $form_id Form ID
* @param array $fields Submitted form fields
* @return string
*/
function wpf_custom_redirect( $url, $form_id, $fields ) {
// Only consider changing the redirect if its for form #50
if ( '50' == $form_id ) {
// In the example below, we look at the submitted value for field #5
// If that value is "test", then we change the redirect URL
if ( !empty( $field['5']['value'] ) && 'test' == $field['5']['value'] ) {
$url = 'https://wpforms.com';
}
}
return $url;
}
add_filter( 'wpforms_process_redirect_url', 'wpf_custom_redirect', 10, 3 );
@joshuafredrickson

This comment has been minimized.

Copy link

@joshuafredrickson joshuafredrickson commented Jun 6, 2017

For this to work, make sure the form's confirmation method is set to "redirect."

@slaFFik

This comment has been minimized.

Copy link

@slaFFik slaFFik commented Sep 1, 2017

Also, not $field but $fields should be in code.
@jaredatch, you might want to fix this typo, otherwise, the snippet above doesn't work.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.