Loving FormAssembly, and I really want to use its advanced features with our lead nurturing application, HubSpot.
I have been struggling to create a contact form in FormAssembly that will properly feed the lead into HubSpot for lead tracking. Reading through HubSpot's API, I'm getting everything into place correctly EXCEPT the hubspot user token value. HubSpot's API examples show how to pull this value via ASP and PHP, but I need to achieve this with Javascript I think.
Here is my sample form that I'm working on as a proof-of-concept: https://secureweb.jax.org/jaxmice/hubspotTest.html
I've created a hidden field called "UserToken", and I pass that field onto HubSpot via the FormAssembly connector feature. However, the javascript I've put into the page is missing the mark, and not populating the cookie value as I'd want.
Is anyone doing anything like this with FormAssembly yet? Anyone here have better Javascript chops than I? (I know the answer to that 2nd one is absolutely YES, I'm not a javascript coder!)
Regards,
Mike Kirby Internet Communcations Manager, JAX Mice & Services The Jackson Laboratory jaxmice.jax.org
Finally, move the whole javascript block (starting at <!-- CODE TO PULL HUBSPOT COOKIE INTO FORM -->) at the bottom of the page (just before the </HTML> tag). That should work.
I would like to give my thanks by writing up a how-to or FAQ item on how to use FormAssembly to feed contact information to HubSpot. Should I just post it as a forum post, or would you like me to submit to you in another way?
Thank you very much Mike, I'm sure it would be very useful to other users. Could you email it to support@formassembly.com? We'll add it to our documentation.
I have run into a problem with how I solved this, hoping you guys can help.
My solution currently involves putting the javascript onto the page after the formassembly form code. The code therefore breaks when a user doesn't correctly enter the CAPTCHA code, and the form refreshes with a version served directly from FormAssembly (because the application-served version doesn't know about my javascript code.
What would be the syntax to convert the following code into a routine I could add into the <script> tag I have in the "Custom Code" window of Advanced Form Properties? I think moving the javascript there would be better anyway, as I could take advantage of the existing submit-action javascript that other code uses (such as the 'verify email address' feature I'm using). Here's the javascript I currently use, which I'm calling via an onClick event on the submit button: <!-- CODE TO PULL HUBSPOT COOKIE INTO FORM --> <script type='text/javascript' language='javascript'> HubSpotForm = function() { // Set the hidden field to contain the user token var results = document.cookie.match ( '(^|;) ?hubspotutk=([^;]*)(;|$)' ); if (results && results[2]) { document.getElementById('tfa_UserToken').value = results[2]; } else if (window['hsut']) { document.getElementById('tfa_UserToken').value = window['hsut']; } return true; }; </script> <!-- END CODE TO PULL HUBSPOT COOKIE INTO FORM -->
The first listener waits for the page to finish loading ( so the submit button exists to be bound to ) and the second listener binds the HubSpotForm function to the onClick event of the submit button.
That should get you a bit closer. Happy to help more.