Skip to content

Instantly share code, notes, and snippets.

@jaredatch
Created March 1, 2017 16:59
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save jaredatch/835334c73939bb35116377a50a3255a8 to your computer and use it in GitHub Desktop.
Save jaredatch/835334c73939bb35116377a50a3255a8 to your computer and use it in GitHub Desktop.
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 );
@pixerize
Copy link

pixerize commented Dec 9, 2021

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