onFormSubmit Not Firing

forms
developertools

#1

Hello

I have a form. Here’s the code:

<!--[if lte IE 8]>
<script charset="utf-8" type="text/javascript" src="//js.hsforms.net/forms/v2-legacy.js"></script>
<![endif]-->
<script charset="utf-8" type="text/javascript" src="https://js.hsforms.net/forms/v2.js"></script>

<script>
hbspt.forms.create({
    css: '',
    portalId: '1946113',
    formId: 'dbb80b0f-244e-48b9-af75-2f977ad63838',
    onFormSubmit: function() {
        // doFormSuccessTracking();
        console.log('test');
    }
});
</script>

OnFormSubmit isn’t firing on Success. Thoughts?


#2

@Nicholas_Cerminara you might need to update your tracking code. I would try and get the fresh embed script from HubSpot and try again. Some of the older embedded tracking scripts did not support the callback in the forms.


#3

Are you guys higher than v2 now?


#4

@Nicholas_Cerminara That is the forms embed code. Do you have the HubSpot tracking code on the page as well?


#5

I didn't know jQuery was required. It just fails silently without it. I ended up mocking a couple jQuery functions and it started working.

/*
This is required to run `onFormSubmit` in the hubspot `form.create({...})` API.
*/
window.jQuery = window.jQuery || (elm => {
  elm.change = () => {};
  elm.trigger = () => {};
  return elm;
});