Submit form on page load (only once)

Hi,

I’m having problems with a jQuery script I’ve written that should submit my GF form on pageload (it’s being pre-populated by another form using GF Easypassthrough Add-on).

The form is firing multiple times on some browsers/user agents such as in-app browsers like Instagram, causing multiple submissions (and automations) as a result.

I’m looking for a solution that can ensure the submit button is only pressed once, regardless of if the page is reloaded or the user goes back.

     jQuery(document).on('gform_post_render', function(){
           if (jQuery("#input_83_1").val().length > 0) {
           jQuery('form#gform_83').trigger('submit');
                console.log("Email sent");
          } else {
  // Do nothing
}
    });

Your script is just triggering the submission, so it’s expected for it do it each time the page is loaded. You would need to improve the script to have a way to know the visitor already submitted the form, for example using a cookie.

Interesting requirement. I’m super curious about the how and why of the multiple submissions which might negate this advice but I thought GF Submit to Access might be a solution for you. By default, it will show the form if the user hasn’t submitted it before and could therefore be automatically submitted. Otherwise, it will load a “completed” message (or it’s original purpose, protected content).

How it’s happening is any method that involves a refresh of the page. That could be intentional or inadvertently, such as revisiting the page from an in-app browser link, or re-opening their iPhone after it’s locked (causing a page reload).

Why it’s happening is because the action is triggered on form render using the specified hook in GF documentation (gform_post_render).

I’m not sure the extension recommended will function for this use case.

I’ve written the below code as a potential solution to the problem:

<script type="text/javascript">
jQuery(document).one('gform_post_render', function() {
	if (!sessionStorage.getItem('gform_post_renderEventTriggered')) {
		sessionStorage.setItem('gform_post_renderEventTriggered', true);
		if (jQuery("#input_83_1").val().length > 0) {
			jQuery('form#gform_83').trigger('submit');
			console.log('Submitted');
		} else {
			console.log('Form is empty');
		}
	} else {
		console.log('Cookie is already set');
	}
});
</script>

I’ll post here with updates on how this performs.

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