Redirection is opening 2 duplicate tabs [RESOLVED]

Hey team,
I have a form that redirects a user from the form to a pdf, the issue I’m having is both methods I’ve tried is causing the redirect to happen twice because of the iframe that’s embedded under the form, in turn running the script twice:

This happens when I do it this way:

add_filter( 'gform_confirmation', function ( $confirmation, $form, $entry, $ajax ) {
    GFCommon::log_debug( __METHOD__ . '(): running.' );

    $forms = array( 2 );

    if ( ! in_array( $form['id'], $forms ) ) {
        return $confirmation;

    if ( isset( $confirmation['redirect'] ) ) {
        $url          = esc_url_raw( $confirmation['redirect'] );
        GFCommon::log_debug( __METHOD__ . '(): Redirect to URL: ' . $url );
        $confirmation = 'Thanks for downloading! A new tab should have opened with the brochure in it. If you have a popup blocker enabled you may need to <a href="">click here to see the brochure.</a>';
        $confirmation .= "<script type=\"text/javascript\">'$url', '_blank');</script>";

    return $confirmation;
}, 10, 4 );

And also when I do it in the confirmation it’s self:

I need to keep AJAX enabled for other functionality. Has anyone found a way around this?

Thanks to a post in the legacy forum I figured out the gform_confirmation_loaded is a better function to use for this purpose. I ended up using the following code to manually set my redirects which open in a new tab and still display a confirmation text on the form page:

In plugin (or functions.php if you put the script in the theme folder, but I want mine to still work regardless of the theme that’s installed so a plugin made more sense:

function gf_redirects_enqueue_script() {
    wp_enqueue_script( 'redirect_gf_script', plugin_dir_url( __FILE__ ) . 'js/redirect-gf.js', array('jquery'), '1.0' );
add_action('wp_enqueue_scripts', 'gf_redirects_enqueue_script');

Then in the script:


        jQuery(document).on('gform_confirmation_loaded', function(event, formId){
            if(formId == 2) {
      'your_redirect_url_goes_here', '_blank');
            } else if(formId == 3) {
      'your_redirect_url_goes_here', '_blank');
            } else if(formId == 4) {
      'your_redirect_url_goes_here', '_blank');
            } else if(formId == 5) {
      'your_redirect_url_goes_here', '_blank');

You can probably pass the redirect url from the gravity forms settings, but when I thought about it more I wanted the client to still be able to edit the confirmation text so I haven’t done this.

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.

© 2008 - 2021. Gravity Forms is a project by Rocketgenius Inc.