What is the best practice for adding JS code to form submissions? If I add a form to a HubSpot page, how can I hook into the form's submit event?
Specifically, I'm trying to add a Facebook pixel event to a form submission. It works intermittently if I add the JS snippet to the "inline thank you message." But it's just not consistent.
Is it possible to use this technique within the "Design Manager," using the Form module? Or do I have to embed the form code using the Custom HTML module?
An alternative method is to have the form redirect to a thank you page and add the facebook pixel event code to that page.
The onFormSubmit method is only possible by using embedded forms as it's part of hbspt.forms.create() call.
So if you have to have your script fire at a specific time, or if you have to stay on the same page I'd suggest use embedded forms. There are some jquery techniques you could try, but they're usually buggy and inconsistent. Otherwise add it to you thank your page.