12% off of LTD using this coupon: TWELVEPERCENTOFF. Promo ends on 2 Dec midnight UTC.
Published on Jun 11, 2021

How to Reload Page After Gravity Forms Form Submission

Sridhar Katakam

In a project I recently finished working on, the requirement was to display a confirmation message followed by automatically refreshing the current page and jumping to the form on the current page once a Gravity Forms form has been submitted so that visitors can re-submit the form if they want to.

The form was present sitewide in the footer.

Confirmations settings in Gravity Forms let us select either Text or Redirect (besides Page) type of confirmation after a form has been submitted. But in this case we need both text and redirect.

gform_confirmation filter to the rescue!

Step 1

Set your form’s confirmation type to Redirect and set any URL (doesn’t matter what, we are going to change it using the filter in the next step) as the Redirect URL.

Gravity Forms Confirmation Type - Redirect

Step 2

Add the form to your page.

Ensure that AJAX is enabled for the form.

Step 3

Add the following sample code in either your child theme’s functions.php or as a Code Snippet:

add_filter( 'gform_confirmation', function ( $confirmation, $form, $entry, $ajax ) {
    GFCommon::log_debug( __METHOD__ . '(): running.' );
    $forms = array( 1 ); // 1 is the form ID
    if ( ! in_array( $form['id'], $forms ) ) {
        return $confirmation;
    if ( isset( $confirmation['redirect'] ) ) {
		// current page url
		global $wp;
		$url = esc_url_raw( home_url( add_query_arg( $_GET, $wp->request ) ) ) . '#gform_wrapper_1';
        GFCommon::log_debug( __METHOD__ . '(): Redirect to URL: ' . $url );

		$confirmation = '<div class="gform_confirmation_wrapper">Thanks for contacting us! We will get back shortly. This page will now refresh so you can re-submit the form if you want to.</div>';
		$confirmation .= "<script type=\"text/javascript\">setTimeout(function () { window.location.assign('$url') }, 3500);</script>";
    return $confirmation;
}, 10, 4 );

Change 1 in $forms = array( 1 ); to the ID of your form.

gform_wrapper_1 at the end of

$url = esc_url_raw( home_url( add_query_arg( $_GET, $wp->request ) ) ) . '#gform_wrapper_1';

is so the visitor can jump to an element with that ID i.e., the form whose ID is 1 after the form submission.

If you just want the page to be reloaded without the jump to anchor, change it to

$url = esc_url_raw( home_url( add_query_arg( $_GET, $wp->request ) ) );

Adjust 3500 to the number of milliseconds you want the page to be refreshed after.

Step 4

Add this CSS:

.gform_confirmation_wrapper {
  padding: 40px;
  background-color: #eee;