APIs & Integrations

Nicholas_Cermin
Member

onFormSubmit Not Firing

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?

0 Upvotes
4 Replies 4
sam_eaton_invis
Member

onFormSubmit Not Firing

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;
});
0 Upvotes
Nicholas_Cermin
Member

onFormSubmit Not Firing

Are you guys higher than v2 now?

0 Upvotes
3PETE
HubSpot Employee
HubSpot Employee

onFormSubmit Not Firing

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

0 Upvotes
3PETE
HubSpot Employee
HubSpot Employee

onFormSubmit Not Firing

@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.

0 Upvotes