HubSpot Forms Global Callback Functions?


Hey HubSpot team & community,

I have been coming across a use case for this more often as of late.

We have a bunch of clients that use Marketo (unfortunately).

One thing I do like about Marketo is their form API seems to be more developer friendly

Here is an example of what I am trying to achieve in plain english:

We store custom data inside cookies to track various interactions with Ad campaigns across various networks that we send through hidden fields inside form submissions.

Unfortunately, the only way to pre-populate this information in HubSpot forms is to use the onFormReady callback that must be defined where the form is embedded.

Marketo on the other hand gives us the ability to listen into when the forms are ready:

    MktoForms2.whenReady(function (form) {
        //populate hidden fields logic here.

Because all of our forms have the same group of hidden fields - it seems redudant and error prone to having to write the same callback function for 10s or 100s of forms on a website.

We can get around this (usually) by using a setTimeout function with a delay of about 1000 milliseconds. But that is assuming that the form is: A) being loaded into the page on load. B) loading before the 1000 millisecond timeout (with some mobile connections and bad internet this can happen frequently. ).

Would it be possible to incorporate something like this? It would make the forms much more powerful - especially when dealing with tracking implementations and sending data to third party applications with AJAX etc…

Please advise!

  • Derek