Created
March 1, 2017 16:59
-
-
Save jaredatch/835334c73939bb35116377a50a3255a8 to your computer and use it in GitHub Desktop.
WPForms conditional form redirects
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 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 ); |
In order for this function to work, one must set desired WPForms confirmation type to "Redirect". I hope I could help someone. Regards
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I'm not sure why the code above doesn't work. I used
wpforms_process_complete
instead from here.My complete code: