I’m trying to create a Download Form so customers enter their details to download a PDF and get redirected to the PDF on submission. I want the PDF/page to open in a new window though and the code I’m using doesn’t do that. When I add the code from (https://docs.gravityforms.com/gform_confirmation/?_ga=2.7552054.587321721.1687398145-1762631046.1684363358#h-4-open-the-page-or-redirect-in-a-new-tab) and adjust the $forms
to ID 1, it actually returns a Text confirmation.
I’m a bit of a newbie and am still learning, so it’s probably something very simple I’ve left out…
This is the code I have used:
add_filter( 'gform_confirmation', function ( $confirmation, $form, $entry, $ajax ) {
GFCommon::log_debug( 'gform_confirmation: running.' );
$forms = array( 1 ); // Target forms with id 3, 6 and 7. Change this to fit your needs.
if ( ! in_array( $form['id'], $forms ) || empty( $confirmation['redirect'] ) ) {
return $confirmation;
}
$url = esc_url_raw( $confirmation['redirect'] );
GFCommon::log_debug( __METHOD__ . '(): Redirect to URL: ' . $url );
$confirmation = 'Thanks for contacting us! We will get in touch with you shortly.';
$confirmation .= GFCommon::get_inline_script_tag( "window.open('$url', '_blank');" );
return $confirmation;
}, 10, 4 );
Any help would be greatly appreciated : )