<?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: How to use the onFormSubmit Global Event in CMS Development</title>
    <link>https://community.hubspot.com/t5/CMS-Development/How-to-use-the-onFormSubmit-Global-Event/m-p/520819#M25935</link>
    <description>&lt;P&gt;Hey&amp;nbsp;&lt;a href="https://community.hubspot.com/t5/user/viewprofilepage/user-id/9259"&gt;@Mike_Eastwood&lt;/a&gt;,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;is there an easy way to get all the fields values when the `onFormSubmit` method gets called? &lt;span class="lia-unicode-emoji" title=":thinking_face:"&gt;🤔&lt;/span&gt;&lt;/P&gt;&lt;P&gt;That method has $form object as an argument instead of the data that will be sent to the submission endpoint.&lt;/P&gt;&lt;P&gt;I know it's possible to listen for messages from the iframe the legacy way&lt;/P&gt;&lt;P&gt;```&lt;/P&gt;&lt;DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;event&lt;/SPAN&gt;&lt;SPAN&gt;.&lt;/SPAN&gt;&lt;SPAN&gt;data&lt;/SPAN&gt;&lt;SPAN&gt;.type&lt;/SPAN&gt; &lt;SPAN&gt;===&lt;/SPAN&gt; &lt;SPAN&gt;'&lt;/SPAN&gt;&lt;SPAN&gt;hsFormCallback&lt;/SPAN&gt;&lt;SPAN&gt;'&lt;/SPAN&gt; &lt;SPAN&gt;&amp;amp;&amp;amp;&lt;/SPAN&gt; &lt;SPAN&gt;event&lt;/SPAN&gt;&lt;SPAN&gt;.&lt;/SPAN&gt;&lt;SPAN&gt;data&lt;/SPAN&gt;&lt;SPAN&gt;.eventName&lt;/SPAN&gt; &lt;SPAN&gt;===&lt;/SPAN&gt; &lt;SPAN&gt;'&lt;/SPAN&gt;&lt;SPAN&gt;onFormSubmit&lt;/SPAN&gt;&lt;SPAN&gt;'&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;```,&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;but that is also a bit weird, IMO, though at least I can get data from the event object in the latter case. 🤷‍&lt;span class="lia-unicode-emoji" title=":male_sign:"&gt;♂️&lt;/span&gt;&lt;/SPAN&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Thu, 04 Nov 2021 09:30:33 GMT</pubDate>
    <dc:creator>AlexeyVorobyov</dc:creator>
    <dc:date>2021-11-04T09:30:33Z</dc:date>
    <item>
      <title>How to use the onFormSubmit Global Event</title>
      <link>https://community.hubspot.com/t5/CMS-Development/How-to-use-the-onFormSubmit-Global-Event/m-p/381523#M19287</link>
      <description>&lt;P&gt;Hi&lt;BR /&gt;Im struggling for hours and cant understand why this doesnt work&lt;/P&gt;&lt;P&gt;please help&lt;BR /&gt;&lt;BR /&gt;Here is what I do :&lt;BR /&gt;1 - Im adding the Listener code to the Template section of "additional markup..." before &amp;lt;/body&amp;gt;&lt;BR /&gt;&lt;BR /&gt;2 - The code looks like this :&lt;BR /&gt;&lt;BR /&gt;window.addEventListener('message', event =&amp;gt; {&lt;BR /&gt;if(event.data.type === 'hsFormCallback' &amp;amp;&amp;amp; event.data.eventName === 'onFormSubmit') {&lt;BR /&gt;$iputherethecodeid.find('input[name="user_agent"]').val(navigator.userAgent).change();&lt;BR /&gt;}&lt;BR /&gt;});&lt;/P&gt;</description>
      <pubDate>Sat, 24 Oct 2020 20:03:04 GMT</pubDate>
      <guid>https://community.hubspot.com/t5/CMS-Development/How-to-use-the-onFormSubmit-Global-Event/m-p/381523#M19287</guid>
      <dc:creator>Ilanyrozen</dc:creator>
      <dc:date>2020-10-24T20:03:04Z</dc:date>
    </item>
    <item>
      <title>Re: How to use the onFormSubmit Global Event</title>
      <link>https://community.hubspot.com/t5/CMS-Development/How-to-use-the-onFormSubmit-Global-Event/m-p/381537#M19288</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://community.hubspot.com/t5/user/viewprofilepage/user-id/138271"&gt;@Ilanyrozen&lt;/a&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Can you move your code to the HubSpot Embed Code?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;For example, you can customise the embed code:&lt;/P&gt;
&lt;LI-CODE lang="markup"&gt;...
hbspt.forms.create({
      portalId: '',
      formId: '',
      onFormSubmit: function($form) {
        // YOUR SCRIPT HERE
        } 
}); 
...&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Here's more detail&amp;nbsp;&lt;A href="https://legacydocs.hubspot.com/docs/methods/forms/advanced_form_options" target="_blank"&gt;https://legacydocs.hubspot.com/docs/methods/forms/advanced_form_options&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;This isn't practical if you want to use your event listeners on multiple pages.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;But, if I want to reuse Custom Form Code (like the example above) I create a Custom Module with the code and then drop the module into my pages.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Does that work for you?&lt;/P&gt;
&lt;P&gt;Mike&lt;/P&gt;</description>
      <pubDate>Sun, 25 Oct 2020 21:59:10 GMT</pubDate>
      <guid>https://community.hubspot.com/t5/CMS-Development/How-to-use-the-onFormSubmit-Global-Event/m-p/381537#M19288</guid>
      <dc:creator>Mike_Eastwood</dc:creator>
      <dc:date>2020-10-25T21:59:10Z</dc:date>
    </item>
    <item>
      <title>Re: How to use the onFormSubmit Global Event</title>
      <link>https://community.hubspot.com/t5/CMS-Development/How-to-use-the-onFormSubmit-Global-Event/m-p/520819#M25935</link>
      <description>&lt;P&gt;Hey&amp;nbsp;&lt;a href="https://community.hubspot.com/t5/user/viewprofilepage/user-id/9259"&gt;@Mike_Eastwood&lt;/a&gt;,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;is there an easy way to get all the fields values when the `onFormSubmit` method gets called? &lt;span class="lia-unicode-emoji" title=":thinking_face:"&gt;🤔&lt;/span&gt;&lt;/P&gt;&lt;P&gt;That method has $form object as an argument instead of the data that will be sent to the submission endpoint.&lt;/P&gt;&lt;P&gt;I know it's possible to listen for messages from the iframe the legacy way&lt;/P&gt;&lt;P&gt;```&lt;/P&gt;&lt;DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;event&lt;/SPAN&gt;&lt;SPAN&gt;.&lt;/SPAN&gt;&lt;SPAN&gt;data&lt;/SPAN&gt;&lt;SPAN&gt;.type&lt;/SPAN&gt; &lt;SPAN&gt;===&lt;/SPAN&gt; &lt;SPAN&gt;'&lt;/SPAN&gt;&lt;SPAN&gt;hsFormCallback&lt;/SPAN&gt;&lt;SPAN&gt;'&lt;/SPAN&gt; &lt;SPAN&gt;&amp;amp;&amp;amp;&lt;/SPAN&gt; &lt;SPAN&gt;event&lt;/SPAN&gt;&lt;SPAN&gt;.&lt;/SPAN&gt;&lt;SPAN&gt;data&lt;/SPAN&gt;&lt;SPAN&gt;.eventName&lt;/SPAN&gt; &lt;SPAN&gt;===&lt;/SPAN&gt; &lt;SPAN&gt;'&lt;/SPAN&gt;&lt;SPAN&gt;onFormSubmit&lt;/SPAN&gt;&lt;SPAN&gt;'&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;```,&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;but that is also a bit weird, IMO, though at least I can get data from the event object in the latter case. 🤷‍&lt;span class="lia-unicode-emoji" title=":male_sign:"&gt;♂️&lt;/span&gt;&lt;/SPAN&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 04 Nov 2021 09:30:33 GMT</pubDate>
      <guid>https://community.hubspot.com/t5/CMS-Development/How-to-use-the-onFormSubmit-Global-Event/m-p/520819#M25935</guid>
      <dc:creator>AlexeyVorobyov</dc:creator>
      <dc:date>2021-11-04T09:30:33Z</dc:date>
    </item>
  </channel>
</rss>

