APIs & Integrations

zendersto
Membre

Pass HSContent cookie value to hidden form field

Hi guys, long story short

Im creating a survey with a custom form and I develop with CUSTOM MODULE in hubspot. I finished  the form with the opening like this:

<form id="msform" action="https://forms.hubspot.com/uploads/form/v2/5435007/bb741987-d401-482b-86b3-13ebf0405ec4" method="post">

but when I tried to submit, it said my IP address cookie was not being passed so I have to add a hidden field :

<input type="hidden" id="something" name="hs_context" value="">

I follow this documentation: 

https://developers.hubspot.com/docs/methods/forms/submit_form

 

and what I needed to do is pulling the cookie from this REQUEST BODY with the example like this:

 

hs_context=%7B%22hutk%22%3A%2260c2ccdfe4892f0fa0593940b12c11aa%22%2C%22ipAddress%22%3A%22192.168.1.12%22%2C%22pageUrl%22%3A%22http%3A%2F%2Fdemo.hubapi.com%2Fcontact%2F%22%2C%22pageName%22%3A%22Contact%2BUs%22%2C%22redirectUrl%22%3A%22http%3A%2F%2Fdemo.hubapi.com%2Fthank-you%2F%22%7D

Im gonna use javascript to do this task, can someone help me with a full functional code to help me achieve this?

 

0 Votes
1 RĂ©ponse
WendyGoh
HubSpot Employee
HubSpot Employee

Pass HSContent cookie value to hidden form field

Hi @zendersto,

 

I hope all is well with you 😄

 

When looking to get the cookie from the hs_context, you can use something like this:

function hubspotCookie() {
  return document.cookie.replace(/(?:(?:^|.*;\s*)hubspotutk\s*\=\s*([^;]*).*$)|^.*$/, "$1");
}

 

As reference from this documentation: Integrating Hubspot with Inspectlet – Inspectlet.

 

Hope this helps to clarify!

0 Votes