<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Submit Cookie Values Upon Form Submission in CMS Development</title>
    <link>https://community.hubspot.com/t5/CMS-Development/Submit-Cookie-Values-Upon-Form-Submission/m-p/900527#M44611</link>
    <description>&lt;P&gt;We'd be interested in a common solution here as well, as we are trying to achieve exactly the same&lt;/P&gt;&lt;P&gt;Thanks!&lt;/P&gt;</description>
    <pubDate>Thu, 04 Jan 2024 07:13:54 GMT</pubDate>
    <dc:creator>klu2</dc:creator>
    <dc:date>2024-01-04T07:13:54Z</dc:date>
    <item>
      <title>Submit Cookie Values Upon Form Submission</title>
      <link>https://community.hubspot.com/t5/CMS-Development/Submit-Cookie-Values-Upon-Form-Submission/m-p/775859#M44608</link>
      <description>&lt;P&gt;Hi All,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have an urgent issue and am hoping someone here has the answer. I am trying to pass a cookie value into a hidden field when my contact form is submitted.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;These are the tools I am using to try and complete this:&lt;/P&gt;&lt;UL&gt;&lt;LI&gt;HubSpot Form&lt;/LI&gt;&lt;LI&gt;Google Tag Manager&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;These are the steps I have taken (this works with other form builders like Gravity Forms, but not with HubSpot forms).&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;OL&gt;&lt;LI&gt;Created a custom field in HubSpot called "msclkid".&lt;/LI&gt;&lt;LI&gt;Added the field "msclkid" to my contact form as a hidden field.&amp;nbsp;&lt;/LI&gt;&lt;LI&gt;Created a cookie on my website via Google Tag Manager that stores the value of the "msclkid" value.&amp;nbsp;&lt;/LI&gt;&lt;LI&gt;Created a custom html tag that passes that msclkid cookie value into the hidden field "msclkid".&lt;/LI&gt;&lt;/OL&gt;&lt;P&gt;Everything works in the process except for step 4.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Here is the code I am using to pass the values into my hidden form field.&amp;nbsp;&lt;STRONG&gt;Keep in mind, HubSpot hidden form fields do not have ids, so I am using the name element.&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;&amp;lt;script&amp;gt;
   // msclkid
   (function () {
  var value = "{{url - msclkid}}" //fill with variable which information should be written into the field
  var selector = "input[name='msclkid']"  //fill with CSS Selector that identifies the form field
  var field = document.querySelector(selector)
  if(field){ field.value = value; }
})();
&amp;lt;/script&amp;gt;&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Does anyone see any issues with my code? The value {{url - msclkid}} is the custom GTM variable for my cookie.&amp;nbsp;&lt;BR /&gt;&lt;BR /&gt;Here is an image of the div for the msclkid:&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Screenshot 2023-03-29 at 4.33.23 PM.png" style="width: 400px;"&gt;&lt;img src="https://community.hubspot.com/t5/image/serverpage/image-id/88360i3BC0E635DC4702F8/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Screenshot 2023-03-29 at 4.33.23 PM.png" alt="Screenshot 2023-03-29 at 4.33.23 PM.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Does anyone have an answer for how I can solve this using only Google Tag Manager? I am open to all ideas!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 29 Mar 2023 22:34:36 GMT</pubDate>
      <guid>https://community.hubspot.com/t5/CMS-Development/Submit-Cookie-Values-Upon-Form-Submission/m-p/775859#M44608</guid>
      <dc:creator>AvesMarketing</dc:creator>
      <dc:date>2023-03-29T22:34:36Z</dc:date>
    </item>
    <item>
      <title>Re: Submit Cookie Values Upon Form Submission</title>
      <link>https://community.hubspot.com/t5/CMS-Development/Submit-Cookie-Values-Upon-Form-Submission/m-p/776333#M44609</link>
      <description>&lt;P&gt;Hello&amp;nbsp;&lt;a href="https://community.hubspot.com/t5/user/viewprofilepage/user-id/537823"&gt;@AvesMarketing&lt;/a&gt;, thank you for posting in our Community!&lt;/P&gt;
&lt;P&gt;I want to invite our top experts to this conversation&amp;nbsp;&lt;a href="https://community.hubspot.com/t5/user/viewprofilepage/user-id/428335"&gt;@jolle&lt;/a&gt;&amp;nbsp;&lt;a href="https://community.hubspot.com/t5/user/viewprofilepage/user-id/76319"&gt;@DanielSanchez&lt;/a&gt;&amp;nbsp;&lt;a href="https://community.hubspot.com/t5/user/viewprofilepage/user-id/91608"&gt;@alyssamwilie&lt;/a&gt;&amp;nbsp;any recommendations for&amp;nbsp;&lt;a href="https://community.hubspot.com/t5/user/viewprofilepage/user-id/537823"&gt;@AvesMarketing&lt;/a&gt;&amp;nbsp;matter?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thank you&lt;/P&gt;
&lt;P&gt;Pam&lt;/P&gt;</description>
      <pubDate>Thu, 30 Mar 2023 20:31:13 GMT</pubDate>
      <guid>https://community.hubspot.com/t5/CMS-Development/Submit-Cookie-Values-Upon-Form-Submission/m-p/776333#M44609</guid>
      <dc:creator>PamCotton</dc:creator>
      <dc:date>2023-03-30T20:31:13Z</dc:date>
    </item>
    <item>
      <title>Re: Submit Cookie Values Upon Form Submission</title>
      <link>https://community.hubspot.com/t5/CMS-Development/Submit-Cookie-Values-Upon-Form-Submission/m-p/779491#M44610</link>
      <description>&lt;P&gt;&lt;a href="https://community.hubspot.com/t5/user/viewprofilepage/user-id/428335"&gt;@jolle&lt;/a&gt;&amp;nbsp;&lt;a href="https://community.hubspot.com/t5/user/viewprofilepage/user-id/76319"&gt;@DanielSanchez&lt;/a&gt;&amp;nbsp;&lt;a href="https://community.hubspot.com/t5/user/viewprofilepage/user-id/91608"&gt;@alyssamwilie&lt;/a&gt;&amp;nbsp;Wanted to follow up with Pam's question and see if you have any insights?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 07 Apr 2023 21:04:00 GMT</pubDate>
      <guid>https://community.hubspot.com/t5/CMS-Development/Submit-Cookie-Values-Upon-Form-Submission/m-p/779491#M44610</guid>
      <dc:creator>AvesMarketing</dc:creator>
      <dc:date>2023-04-07T21:04:00Z</dc:date>
    </item>
    <item>
      <title>Re: Submit Cookie Values Upon Form Submission</title>
      <link>https://community.hubspot.com/t5/CMS-Development/Submit-Cookie-Values-Upon-Form-Submission/m-p/900527#M44611</link>
      <description>&lt;P&gt;We'd be interested in a common solution here as well, as we are trying to achieve exactly the same&lt;/P&gt;&lt;P&gt;Thanks!&lt;/P&gt;</description>
      <pubDate>Thu, 04 Jan 2024 07:13:54 GMT</pubDate>
      <guid>https://community.hubspot.com/t5/CMS-Development/Submit-Cookie-Values-Upon-Form-Submission/m-p/900527#M44611</guid>
      <dc:creator>klu2</dc:creator>
      <dc:date>2024-01-04T07:13:54Z</dc:date>
    </item>
    <item>
      <title>Re: Submit Cookie Values Upon Form Submission</title>
      <link>https://community.hubspot.com/t5/CMS-Development/Submit-Cookie-Values-Upon-Form-Submission/m-p/1224793#M44612</link>
      <description>&lt;P&gt;I'm having the same issue.&amp;nbsp;I am also trying to pass a first-party cookie value into a custom hidden field on HubSpot on form submission. I have searched high and low all over the Hubspot community forums, YouTube, everywhere, and have found no answers. I can't believe this is not possible. &lt;STRONG&gt;Please somebody from HubSpot respond with an actual solution.&amp;nbsp;&lt;/STRONG&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;P&gt;For those trying to figure this out, here is what I got working (does not trigger any of my debug warnings). The part that fails is the very last step of passing the value to Hubspot on submit.&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;P&gt;Note: this form is embedded in a modal, hence the event listener when the modal is opened. If you're form is directly embedded on the page, you might change the event listener to a regular onload or onready event. Also note: you will need to update the code with your Hubspot ID, Form ID, cookie name, and custom hidden field name as you named it in Hubspot.&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;          &amp;lt;div class="modal-body"&amp;gt;
            &amp;lt;script src="https://js-na2.hsforms.net/forms/embed/developer/REPLACE_WITH_ID.js" async defer&amp;gt;&amp;lt;/script&amp;gt;
            &amp;lt;div class="hs-form-html"
                data-region="na2"
                data-form-id="REPLACE_WITH_FORM_ID"
                data-portal-id="REPLACE_WITH_ID"&amp;gt;&amp;lt;/div&amp;gt;
            &amp;lt;script&amp;gt;
              (function(){
		// gets cookie value for affiliate_id
                function getAffiliateCookie() {
                  var name = "affiliate_id=";
                  var decoded = decodeURIComponent(document.cookie);
                  var parts = decoded.split(';');
                  for (var i = 0; i &amp;lt; parts.length; i++) {
                    var c = parts[i].trim();
                    if (c.indexOf(name) === 0) {
                      return c.substring(name.length, c.length);
                    }
                  }
                  return "";
                }
                var affiliateValue = getAffiliateCookie();
                console.log("[Debug] Found affiliate_id cookie value:", affiliateValue);

                function runAfterModal() {
                  setTimeout(function(){
                    try {
                      var container = document.querySelector('.hs-form-html[data-form-id="REPLACE_WITH_FORM_ID"]');
                      if (!container) {
                        console.warn("[Debug] HubSpot form container not found.");
                        return;
                      }
 		      // drill down through hubspot class names to targeted input field, replace with your own 	
                      var field = document.querySelector('[data-hs-island="true"] .hsfc-Renderer .hsfc-Form .hsfc-Step__Content .hsfc-Row input[name="0-1/affiliate"]');
                      if (!field) {
                        console.log("[Debug] Can't find hidden field affiliate");
                      }
                      field.value = affiliateValue || "";
                      console.log("[Debug] Affiliate field set to:", field.value);
                    } catch(err) {
                      console.error("[Debug] Error setting affiliate field:", err);
                    }
                  }, 600);  // 600ms delay
                }
                // listen for click to open modal
                document.addEventListener("click", function(e) {
                  var el = e.target;
                  while (el &amp;amp;&amp;amp; el !== document) {
                    if (el.getAttribute &amp;amp;&amp;amp; el.getAttribute("data-target") === "#modalhubspot") {
                      console.log("[Debug] Detected click on HubSpot modal trigger.");
                      runAfterModal();
                      break;
                    }
                    el = el.parentNode;
                  }
                });

              })();
            &amp;lt;/script&amp;gt;
          &amp;lt;/div&amp;gt;&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 17 Nov 2025 20:32:40 GMT</pubDate>
      <guid>https://community.hubspot.com/t5/CMS-Development/Submit-Cookie-Values-Upon-Form-Submission/m-p/1224793#M44612</guid>
      <dc:creator>mbird22</dc:creator>
      <dc:date>2025-11-17T20:32:40Z</dc:date>
    </item>
    <item>
      <title>Re: Submit Cookie Values Upon Form Submission</title>
      <link>https://community.hubspot.com/t5/CMS-Development/Submit-Cookie-Values-Upon-Form-Submission/m-p/1228545#M44613</link>
      <description>&lt;P&gt;Hi &lt;SPAN style="background: var(--ck-color-mention-background); color: var(--ck-color-mention-text);"&gt;&lt;a href="https://community.hubspot.com/t5/user/viewprofilepage/user-id/991464"&gt;@mbird22&lt;/a&gt;&lt;/SPAN&gt; and a big warm welcome! We’re so happy you’ve joined us here.&lt;BR /&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thank you for reaching out to the HubSpot Community, and I sincerely appreciate your patience as we got back to you.&lt;BR /&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Could you share if the form you’re working with was created in the new editor?&lt;BR /&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;In the meantime, here are some helpful resources you might find useful:&lt;BR /&gt;&lt;BR /&gt;- &lt;A href="https://developers.hubspot.com/docs/api-reference/global-form-events/guide" target="_blank"&gt;Global form events&lt;/A&gt;&lt;BR /&gt;- &lt;A href="https://developers.hubspot.com/docs/cms/start-building/features/forms/legacy-forms" target="_blank"&gt;Legacy forms&lt;/A&gt;&lt;BR /&gt;&lt;BR /&gt;And let’s see if some of our wonderful experts can chime in as well! Hi &lt;SPAN style="background: var(--ck-color-mention-background); color: var(--ck-color-mention-text);"&gt;&lt;a href="https://community.hubspot.com/t5/user/viewprofilepage/user-id/321717"&gt;@MichaelMa&lt;/a&gt;&lt;/SPAN&gt;, &lt;SPAN style="background: var(--ck-color-mention-background); color: var(--ck-color-mention-text);"&gt;&lt;a href="https://community.hubspot.com/t5/user/viewprofilepage/user-id/9259"&gt;@Mike_Eastwood&lt;/a&gt;&lt;/SPAN&gt; and &lt;SPAN style="background: var(--ck-color-mention-background); color: var(--ck-color-mention-text);"&gt;&lt;a href="https://community.hubspot.com/t5/user/viewprofilepage/user-id/63499"&gt;@SteveHTM&lt;/a&gt;&lt;/SPAN&gt; do you have any suggestions or insights to support &lt;SPAN style="background: var(--ck-color-mention-background); color: var(--ck-color-mention-text);"&gt;&lt;a href="https://community.hubspot.com/t5/user/viewprofilepage/user-id/991464"&gt;@mbird22&lt;/a&gt;&lt;/SPAN&gt;, please?&lt;BR /&gt;&lt;BR /&gt;Wishing you a fantastic day and thanks you so much!&lt;BR /&gt;Bérangère&lt;/P&gt;</description>
      <pubDate>Wed, 26 Nov 2025 07:42:37 GMT</pubDate>
      <guid>https://community.hubspot.com/t5/CMS-Development/Submit-Cookie-Values-Upon-Form-Submission/m-p/1228545#M44613</guid>
      <dc:creator>BérangèreL</dc:creator>
      <dc:date>2025-11-26T07:42:37Z</dc:date>
    </item>
    <item>
      <title>Re: Submit Cookie Values Upon Form Submission</title>
      <link>https://community.hubspot.com/t5/CMS-Development/Submit-Cookie-Values-Upon-Form-Submission/m-p/1231360#M44674</link>
      <description>&lt;P data-unlink="true"&gt;&lt;FONT color="#000000"&gt;Hello&amp;nbsp;BérangèreL,&lt;BR /&gt;&lt;BR /&gt;Thank you for responding. I'm new to HubSpot, I didn't realize there was more than one form editor. After checking, it appears I am using the new editor. I see in the Global Form events resource you shared that there is a setFieldValue method. I have not tried it yet, but hopefully this can solve my problem. I will reply tomorrow when I test.&lt;BR /&gt;&lt;BR /&gt;Thank you again for your help,&lt;BR /&gt;Emily&amp;nbsp;&lt;/FONT&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 05 Dec 2025 06:57:54 GMT</pubDate>
      <guid>https://community.hubspot.com/t5/CMS-Development/Submit-Cookie-Values-Upon-Form-Submission/m-p/1231360#M44674</guid>
      <dc:creator>mbird22</dc:creator>
      <dc:date>2025-12-05T06:57:54Z</dc:date>
    </item>
    <item>
      <title>Re: Submit Cookie Values Upon Form Submission</title>
      <link>https://community.hubspot.com/t5/CMS-Development/Submit-Cookie-Values-Upon-Form-Submission/m-p/1231564#M44683</link>
      <description>&lt;P&gt;I found a solution! It looks like Hubspot code was re-rendering the form after the modal opened. But after setting some safe guards, everything works. I ended up still using vanilla javascript method to get and set. But in the future will likely clean this up with setFieldValue method, which looks more elegant. Thanks again for your help.&lt;/P&gt;</description>
      <pubDate>Fri, 05 Dec 2025 20:57:26 GMT</pubDate>
      <guid>https://community.hubspot.com/t5/CMS-Development/Submit-Cookie-Values-Upon-Form-Submission/m-p/1231564#M44683</guid>
      <dc:creator>mbird22</dc:creator>
      <dc:date>2025-12-05T20:57:26Z</dc:date>
    </item>
    <item>
      <title>Re: Submit Cookie Values Upon Form Submission</title>
      <link>https://community.hubspot.com/t5/CMS-Development/Submit-Cookie-Values-Upon-Form-Submission/m-p/1231851#M44684</link>
      <description>&lt;P&gt;Great to hear you found a solution &lt;SPAN style="background: var(--ck-color-mention-background); color: var(--ck-color-mention-text);"&gt;&lt;a href="https://community.hubspot.com/t5/user/viewprofilepage/user-id/991464"&gt;@mbird22&lt;/a&gt;&lt;/SPAN&gt;!&lt;BR /&gt;&lt;BR /&gt;Thanks for sharing your approach, and feel free to keep us posted as you refine it further.&lt;BR /&gt;&lt;BR /&gt;Have a lovely day!&lt;BR /&gt;Bérangère&lt;/P&gt;</description>
      <pubDate>Mon, 08 Dec 2025 08:10:50 GMT</pubDate>
      <guid>https://community.hubspot.com/t5/CMS-Development/Submit-Cookie-Values-Upon-Form-Submission/m-p/1231851#M44684</guid>
      <dc:creator>BérangèreL</dc:creator>
      <dc:date>2025-12-08T08:10:50Z</dc:date>
    </item>
  </channel>
</rss>

