# Redirect Gravity Forms Based on an Answer

> Sends people to a different page after submitting a Gravity Forms form depending on what they chose in one field, such as a sales or support thank-you page.

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

## Code

```php
$wpide_gf_redirect_form  = 0;  // Form ID (0 = off until you set it).
$wpide_gf_redirect_field = 6;  // Field ID holding the answer.
// Answer value => URL.
$wpide_gf_redirect_map = array(
    'sales'   => '/thank-you-sales/',
    'support' => '/thank-you-support/',
);

add_filter( 'gform_confirmation_' . $wpide_gf_redirect_form, function ( $confirmation, $form, $entry ) use ( $wpide_gf_redirect_field, $wpide_gf_redirect_map ) {
    $answer = (string) rgar( $entry, (string) $wpide_gf_redirect_field );

    if ( isset( $wpide_gf_redirect_map[ $answer ] ) ) {
        return array( 'redirect' => esc_url_raw( home_url( $wpide_gf_redirect_map[ $answer ] ) ) );
    }

    return $confirmation;
}, 10, 3 );
```

## Notes

Set the form ID, field ID and the value-to-URL map at the top; other answers keep the form's normal confirmation.

## How to use it

Install the free WPIDE plugin (https://wordpress.org/plugins/wpide/), find "Redirect Gravity Forms 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/
