-
-
Save slaFFik/ff355fe1d3f2ba8670691852112b5912 to your computer and use it in GitHub Desktop.
WPForms: Conditional form redirects based on field value.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* WPForms: Conditional form redirects based on field value. | |
* | |
* @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( $fields['5']['value'] ) && 'test' == $fields['5']['value'] ) { | |
$url = 'https://wpforms.com'; | |
} | |
} | |
return $url; | |
} | |
add_filter( 'wpforms_process_redirect_url', 'wpf_custom_redirect', 10, 3 ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment