Is the forms javascript onFormSubmit a blocking function?


#1

We use Google Tag Manager to send tracking events on a successful form submission. Our form submission redirects the user to a new page after success.

A few posts here indicate that some users are attaching to a .hsvalidatedsubmit function and the Hubspot documentation refers to the onFormSubmit function. What I’m not seeing is any clarification about whether any of these events are blocking…

My goal is to ensure that my tag events are triggered before the form redirects the user. Do the onFormSubmit and .hsvalidatedsubmit calls both wait for a return or are they asynchronous like most javascript?

I think you can see what I’m getting at here but if not I’ll be happy to clarify.


#2

Hi @Arlo_Gilbert

The hsvalidatedsubmit event is triggered after the data in a HubSpot form passes validation. You can detect when that event is triggered, but anything you do after detecting the event would not block the submission from proceeding.

The onFormSubmit function gets executed as part of the submission itself, so anything you include in that function will be executed before the form proceeds with the submission.


Trigger Google Analytics Event with Form Submission
#3

Ok so if I understand you correctly you’re suggesting that onFormSubmit is the correct mechanism for us to use, correct?

onFormSubmit is only triggered after the form has completed validation but before the form is actually submitted?


#4

@Arlo_Gilbert you are correct; onFormSubmit is called after validation passes, right before the form data is actually sent to HubSpot, and if you can add onFormSubmit to the embed code it’s going to be a better solution than listening for the hsvalidatedsubmit event.