The gform_suppress_confirmation_redirect filter allows you to suppress the default page or redirect confirmation type behavior after form submission.
Usage
To apply the filter to all forms, use the following code:
add_filter('gform_suppress_confirmation_redirect', '__return_true');
Parameters
- $suppress_redirect (bool): Indicates whether the confirmation redirect header should be suppressed. Defaults to false.
More information
See Gravity Forms Docs: gform_suppress_confirmation_redirect
This filter was added in Gravity Forms version 2.3 and should be placed in the functions.php
file of your active theme.
Source code location:
form_display.php
: GFFormDisplay::process_form() and GFFormDisplay::handle_confirmation()api.php
: GFAPI::submit_form()
Examples
Suppress redirect for a specific form
Suppress the confirmation redirect for form ID 5:
add_filter('gform_suppress_confirmation_redirect', function ($suppress_redirect, $form) { if ($form['id'] == 5) { return true; } return $suppress_redirect; }, 10, 2);
Open redirect in a new tab
Override the default behavior to open the redirect in a new tab:
add_filter('gform_confirmation', function ($confirmation, $form) { if (isset($confirmation['redirect'])) { $confirmation['redirect'] = 'javascript:window.open("' . $confirmation['redirect'] . '");'; } return $confirmation; }, 10, 2); add_filter('gform_suppress_confirmation_redirect', '__return_true');
Suppress redirect based on user role
Suppress the confirmation redirect for users with the ‘subscriber’ role:
add_filter('gform_suppress_confirmation_redirect', function ($suppress_redirect) { if (current_user_can('subscriber')) { return true; } return $suppress_redirect; });
Suppress redirect for a specific form field value
Suppress the confirmation redirect for form ID 7 when a specific field (field ID 2) has the value ‘No Redirect’:
add_filter('gform_suppress_confirmation_redirect', function ($suppress_redirect, $form) { if ($form['id'] == 7 && rgpost('input_2') == 'No Redirect') { return true; } return $suppress_redirect; }, 10, 2);
Display a custom message instead of redirect
Suppress the redirect confirmation and display a custom message for form ID 12:
add_filter('gform_suppress_confirmation_redirect', function ($suppress_redirect, $form) { if ($form['id'] == 12) { return true; } return $suppress_redirect; }, 10, 2); add_filter('gform_confirmation', function ($confirmation, $form) { if ($form['id'] == 12) { $confirmation = '<div class="alert alert-success">Thank you! Your submission has been received.</div>'; } return $confirmation; }, 10, 2);