# Redirect WPForms Based on an Answer

> Sends visitors to a different thank-you page after a WPForms form depending on the option they picked, such as separate pages for sales and support.

- Type: PHP
- Runs: Run everywhere
- Category: [Forms](https://wpide.com/library/category/forms/)
- Tags: wpforms, redirect, conditional
- Author: WPIDE Team
- Installs: 0
- Updated: 2026-10-28
- Page: https://wpide.com/library/wpforms-redirect-by-answer/

## Code

```php
$wpide_wpf_redirect_form  = 0; // Form ID (0 = off until you set it).
$wpide_wpf_redirect_field = 6; // Field ID with the answer.
// Answer label => URL.
$wpide_wpf_redirect_map = array(
    'Sales'   => '/thank-you-sales/',
    'Support' => '/thank-you-support/',
);

add_filter( 'wpforms_process_redirect_url', function ( $url, $form_id, $fields ) use ( $wpide_wpf_redirect_form, $wpide_wpf_redirect_field, $wpide_wpf_redirect_map ) {
    if ( (int) $form_id !== $wpide_wpf_redirect_form ) {
        return $url;
    }

    $answer = isset( $fields[ $wpide_wpf_redirect_field ]['value'] ) ? (string) $fields[ $wpide_wpf_redirect_field ]['value'] : '';

    return isset( $wpide_wpf_redirect_map[ $answer ] ) ? esc_url_raw( home_url( $wpide_wpf_redirect_map[ $answer ] ) ) : $url;
}, 10, 3 );
```

## Notes

Set the form ID, field ID and map at the top, and set the form's confirmation type to "Go to URL (Redirect)" with a fallback URL that this snippet swaps by answer.

## How to use it

Install the free WPIDE plugin (https://wordpress.org/plugins/wpide/), find "Redirect WPForms Based on an Answer" in its snippet library and add it in one click; or create a new PHP snippet in WPIDE (or any code snippets plugin) and paste the code above. More snippets: https://wpide.com/library/
