How to automatically reload a Gravity Form when a modal is closed

A simple way to reload a Gravity Form in a modal when the modal is closed; resetting the form to it’s original state.

This article requires the Gravity Forms Reload Form perk.

Buy Gravity Perks to get this perk plus 47 other premium Gravity Forms plugins!

View Plugin Buy Gravity Perks

By default GP Reload Form will provide the ability to add a link that when clicked will reload a Gravity Form automatically. It also has support for reloading a form after a specific time in seconds.

We recently had a Gravity Perks user request support for allowing a Gravity Form in a modal to automatically reload when the modal was closed.

So for example, a user visits your site and fills out part of a Gravity Form or there are validation errors on the Gravity Form in a modal, then the user exits the modal where the form is located, you may want to “reset” the form back to its default state.

We have now added support for this feature with GP Reload Form. This article will show you how to automatically reload a Gravity Form when a modal is closed!

Steps

  1. Enable GP Reload Form.
  2. Add jQuery snippet to a callback event.

1. Enable GP Reload Form

  1. Visit the form you would like to use in your modal
  2. Select “Settings” from the Form Menu to visit the “Form Settings” page
  3. Scroll to the bottom of this page and select the “Automatically Reload Form” option. There will also be an option that appears labeled “Seconds until Reload.” Leave this option empty.
gp-reload-form-option

2. Add jQuery snippet to a callback event

  1. Copy and paste the snippet that corresponds to your modal of choice (see Usage Examples below).
  2. Update the selected usage example to use your own form ID. All of the usage examples are based on a form ID of 82; replace with your own form ID.

Usage Examples

  1. Magnific Popup
  2. Fancybox
  3. Popup Maker

Magnific Popup Example

This is an example of how you would setup this functionality using Magnific Popup

// Update ".open-popup" to the selector for the element that will open the modal.
$( '.open-popup' ).magnificPopup( {
	type:'inline',
	callbacks: {
		close: function() {
			// Update "82" to the ID of the form within the modal.
			var gwrf = window.gwrf_82;
			if( typeof gwrf != 'undefined' ) {
				gwrf.reloadForm();
			}
		}
	}
} );

Bind to an already initialized Magnific Popup

Here is an example of how you would bind this to a Magnific Popup that has already been initialized elsewhere.

// Update ".open-popup" to the selector for the element that has been previoulsy been initialized with Magnific.
$( '.open-popup' ).on( 'mfpClose', function() {
	// Update "82" to the ID of the form within the modal.
	var gwrf = window.gwrf_82;
	if ( typeof gwrf != 'undefined' ) {
		gwrf.reloadForm();
	}
} );

Fancybox Example

This is an example of how you would set up this functionality using Fancybox Popup

// Update ".open-popup" to the selector for the element that will open the modal.
$( '.open-popup' ).fancybox( {
	afterClose: function() {
		// Update "82" to the ID of the form within the modal.
		var gwrf = window.gwrf_82;
		if ( typeof gwrf != 'undefined' ) {
			gwrf.reloadForm();
		}
	}
} );

Bind to an already initialized Fancybox Popup

Here is an example of how you would bind this to a Fancybox Popup that has already been initialized elsewhere.

$( document ).on( 'afterClose', function() {
	// Update "82" to the ID of the form within the modal.
	var gwrf = window.gwrf_82;
	if( typeof gwrf != 'undefined' ) {
		gwrf.reloadForm();
	}
} );

Popup Maker (formerly Easy Modal) Example

This is an example of how you would set up this functionality using Popup Maker

// Update "13256" to the ID of your modal.
$( '#pum-13256' ).on( 'pumAfterClose', function() {
	// Update "82" to the ID of the form within the modal.
	var gwrf = window.gwrf_82;
	if( typeof gwrf != 'undefined' ) {
		gwrf.reloadForm();
	}
} );

Since Popup Maker is a plugin solution, setting this up will be a little different. You’ll notice that the trigger we are using in the example above is “#pum-13256”.

When you create a Popup Maker popup, they will automatically assign you a trigger class, which you can find on the All Popups page. In the example above, this class is “popmake-13256”.

This class is the trigger for the popup to appear on a page. So you just need to identify this class and the number value will be what you use in the snippet above.

popup-maker-popups

Digging Deeper

The above examples will work out of the box with quick changes to the Form ID and modal triggers, but what about other modal options?

This is the base code that enables this functionality and it can be used in conjunction with any modal.

// Update "82" to the ID of the form within the modal.
var gwrf = window.gwrf_82;
if ( typeof gwrf !== 'undefined' ) {
    gwrf.reloadForm();
}

In order to activate it with other modals, you’ll need to:

  1. Identify the trigger for the modal. This can be something you set yourself or that is already set by the plugin you are using.
  2. Identify the callback close event for the modal. Each modal solution will have a callback that fires when the modal is closed. You just need to add the snippet to that callback.
  3. For plugin solutions such as Popup Maker, you aren’t handling the initialization manually so you instead identify the modal close event being used by the plugin then apply the snippet above to it. In the case of Popup Maker, there is a close event called pumAfterClose so you would need to find the equivalent event in the modal plugin you are using.

We hope you find this useful!

Did this help you out? Let us know in the comments below!

Comments

  1. Jim Henderson
    Jim Henderson November 19, 2022 at 10:36 am

    I want to report a bug present in the GP Reload Form. Here is a way to repeat it: 1. There are 2 buttons on the page that open popups (popup_1 and popup_2) with 2 different Gravity Forms (form_1 and form_2) with AJAX confirmation. 2. Added {reload_form} links to reload the form in the confirmation message in both forms. (Actually, it works with a timed reload as well) 3. Next, you need to fill out form_1, click “send” and close the popup without reloading the form. 4. Next, you need to fill out form_2, click “send” and close the popup without reloading the form. 5. And now the magic: the first popup that will be opened again (with a confirmation message and a link to reload the form), and in which the reload of the form will be launched first, broadcasts its form to both popups. That is, if you open popup_2 and click the {reload_form} link, then opening popup_1 you will see form_1 instead of form_2.

    Reply
    1. Samuel Bassah
      Samuel Bassah Staff November 21, 2022 at 7:50 am

      Hi Jim,

      Thanks for the detailed steps to recreate this issue. I’m passing this over to our developers to look into it. We’ll update this comment when there is more information on the issue.

      Best,

    2. Samuel Bassah
      Samuel Bassah Staff November 28, 2022 at 12:16 pm

      Hi Jim,

      This issue has been fixed and will be available in the next update of GP Reload Forms Perk. If you have an active Gravity Perks license, you can contact us via our support form, so we can send you a link to download the new version before it’s publicly released.

      https://gravitywiz.com/support/

      Best,

  2. Jim Henderson
    Jim Henderson October 9, 2022 at 4:46 pm

    I am using GP Reload Form and have run into a problem. I have connected an external script file for formatting the phone input field (masked input). And when using GP Reload Form, this script stops working. What could be the problem?

    Му code: https://snippi.com/s/inqc7yx

    Reply
    1. Samuel Bassah
      Samuel Bassah Staff October 10, 2022 at 8:37 am

      Hi Jim,

      Unfortunately, we’re unable to provide support for custom snippets in the comment section. If you have an active Gravity Perks Pro license, you can get in touch with us via the support form and we can have our developers take a look at your code and see how we can get our Perk working with your codes.

      Best,

  3. Eric Mueller
    Eric Mueller February 3, 2022 at 7:45 pm

    Looks like this breaks the confirmations function. Instead of redirecting to my confirmation page it just shows a weird message.

    Reply
    1. Samuel Bassah
      Samuel Bassah Staff February 8, 2022 at 4:37 am

      Hi Eric,

      If an active Gravity Perks License, you can get in touch with us via our support form with additional information so that we can dig into this further to help resolve the issue you’re experiencing.

      Best,

  4. Andrea
    Andrea October 14, 2021 at 11:02 am

    Hi! I do need this feature but something is not clear to me. I tried the demo and I can see submitted forms aren’t reloaded on modal closed. Only partially filled forms are reloaded. Would it be possible with your plugin? Thanks

    Reply
    1. Dario Space
      Dario Space October 14, 2021 at 11:13 am

      Hi Andrea,

      This tutorial requires GP Reload Form Perk.

      If you have an active Gravity Perks License, you can get in touch with us via our support form with your account email address and we’ll be happy to dig into this further.

      Best,

  5. Melody Sinks
    Melody Sinks February 19, 2021 at 5:03 pm

    I was able to make this work within a popup. Is there a way to have the form NOT save previous field data? My site visitors sometimes need to fill out this same form several times, signing up for alerts. I need a fresh form each time the form reloads.

    Reply
    1. Samuel Bassah
      Samuel Bassah Staff February 22, 2021 at 6:13 am

      Hi Melody,

      You can disable this feature by adding the snippet below to your theme’s functions.php file:

      add_filter( 'gprf_disable_dynamic_reload', '__return_true' );

      Best,

    1. Samuel Bassah
      Samuel Bassah Staff August 20, 2020 at 7:20 am

      Hi Bhavik,

      That’s a bit strange because the demo is working on my end. Could you explain how you’re testing it on your end?

      Best,

  6. College Dawson
    College Dawson March 16, 2020 at 6:55 pm

    This doesn’t seem to work as expected when there are validation errors on the form. How would you completely reload a form even if it has validation errors?

    Reply
  7. Zach Nicodemous
    Zach Nicodemous February 13, 2020 at 2:02 pm

    The Gravity Perks Reload Form plugin does not seem to be working with the latest versions of Gravity Forms. One of my client has this on their website; we have Gravity Perks enabled, along with the Reload Form perk but the “GP Reload Form” section does not appear in their form settings and under confirmations, the “Reload Form” item does not appear in the dropdown.

    Given that this is a paid plugin, you should get this resolved ASAP.

    Reply
    1. Scott Ryer
      Scott Ryer Staff February 13, 2020 at 2:31 pm

      Hi Zach, in most cases the cause of this is an install error. Deactivate and delete the Perk, download a fresh copy from your account, and install that on your site.

      If that doesn’t fix the problem, drop us a line at support and we’ll be happy to take a look.

Leave a Reply

Your email address will not be published. Required fields are marked *

  • Trouble installing this snippet? See our troubleshooting tips.
  • Need to include code? Create a gist and link to it in your comment.
  • Reporting a bug? Provide a URL where this issue can be recreated.

By commenting, I understand that I may receive emails related to Gravity Wiz and can unsubscribe at any time.

Download Snippet

How to automatically reload a Gravity Form when a modal is closed

This field is for validation purposes and should be left unchanged.