<?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: Onsubmit function in multistep beta forms in Lead Capture Tools</title>
    <link>https://community.hubspot.com/t5/Lead-Capture-Tools/Onsubmit-function-in-multistep-beta-forms/m-p/1033360#M11916</link>
    <description>&lt;P&gt;Its been a little bit since i have done this, but I am pretty sure i did something like this. I used to GPT to quickly jot out what I did before. However recently I was trying to dynamically populate a form with a similar approach and couldnt get it to work, but I didnt try for a long time&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;H3&gt;1. &lt;STRONG&gt;Ensure the Form is Loaded:&lt;/STRONG&gt;&lt;/H3&gt;&lt;UL&gt;&lt;LI&gt;Since the form loads asynchronously via the embed script, you should wait until the form is fully loaded before attaching any event listeners. You can achieve this using the hsFormCallback event or by setting an interval to check when the form is available.&lt;/LI&gt;&lt;/UL&gt;&lt;H3&gt;2. &lt;STRONG&gt;Attach an Event Listener Dynamically:&lt;/STRONG&gt;&lt;/H3&gt;&lt;UL&gt;&lt;LI&gt;Once the form is loaded, attach an onsubmit event listener to the form. This can be done using JavaScript.&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;&amp;lt;script src="https://js.hsforms.net/forms/embed/12345678.js" defer&amp;gt;&amp;lt;/script&amp;gt;
&amp;lt;div class="hs-form-frame" data-region="na1" data-form-id="5da9sdj76-47f8-412d-a98a-659874fv12" data-portal-id="12345678"&amp;gt;&amp;lt;/div&amp;gt;

&amp;lt;script&amp;gt;
// Function to handle form submission
function onHubSpotFormSubmit(event) {
    event.preventDefault(); // Prevent the default form submission if needed
    console.log("Form submitted!");
    // Add your custom code here
}

// Check if the form is loaded and then add the event listener
function attachHubSpotFormSubmitListener() {
    var formElement = document.querySelector('.hs-form-frame form');
    if (formElement) {
        formElement.addEventListener('submit', onHubSpotFormSubmit);
    } else {
        // Retry after a short delay if the form is not yet loaded
        setTimeout(attachHubSpotFormSubmitListener, 100);
    }
}

// Ensure the script runs after the page is fully loaded
document.addEventListener('DOMContentLoaded', function() {
    attachHubSpotFormSubmitListener();
});
&amp;lt;/script&amp;gt;
​&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Wed, 28 Aug 2024 13:11:05 GMT</pubDate>
    <dc:creator>Eric_Hoyer</dc:creator>
    <dc:date>2024-08-28T13:11:05Z</dc:date>
    <item>
      <title>Onsubmit function in multistep beta forms</title>
      <link>https://community.hubspot.com/t5/Lead-Capture-Tools/Onsubmit-function-in-multistep-beta-forms/m-p/1033290#M11915</link>
      <description>&lt;P&gt;The new multistep form has a different embed code. I can't find documentation on how to add an onsubmit function to this new code.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Here is how the current embed code looks.&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;&amp;lt;script src="https://js.hsforms.net/forms/embed/12345678.js" defer&amp;gt;&amp;lt;/script&amp;gt;
&amp;lt;div class="hs-form-frame" data-region="na1" data-form-id="5da9sdj76-47f8-412d-a98a-659874fv12" data-portal-id="12345678"&amp;gt;&amp;lt;/div&amp;gt;&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have also tried using event listeners but there is no event fired after I click submit on the form. Does anyone know how to add an onsubmit function to these new forms? Thanks!&lt;/P&gt;</description>
      <pubDate>Wed, 28 Aug 2024 11:17:39 GMT</pubDate>
      <guid>https://community.hubspot.com/t5/Lead-Capture-Tools/Onsubmit-function-in-multistep-beta-forms/m-p/1033290#M11915</guid>
      <dc:creator>Mart999</dc:creator>
      <dc:date>2024-08-28T11:17:39Z</dc:date>
    </item>
    <item>
      <title>Re: Onsubmit function in multistep beta forms</title>
      <link>https://community.hubspot.com/t5/Lead-Capture-Tools/Onsubmit-function-in-multistep-beta-forms/m-p/1033360#M11916</link>
      <description>&lt;P&gt;Its been a little bit since i have done this, but I am pretty sure i did something like this. I used to GPT to quickly jot out what I did before. However recently I was trying to dynamically populate a form with a similar approach and couldnt get it to work, but I didnt try for a long time&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;H3&gt;1. &lt;STRONG&gt;Ensure the Form is Loaded:&lt;/STRONG&gt;&lt;/H3&gt;&lt;UL&gt;&lt;LI&gt;Since the form loads asynchronously via the embed script, you should wait until the form is fully loaded before attaching any event listeners. You can achieve this using the hsFormCallback event or by setting an interval to check when the form is available.&lt;/LI&gt;&lt;/UL&gt;&lt;H3&gt;2. &lt;STRONG&gt;Attach an Event Listener Dynamically:&lt;/STRONG&gt;&lt;/H3&gt;&lt;UL&gt;&lt;LI&gt;Once the form is loaded, attach an onsubmit event listener to the form. This can be done using JavaScript.&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;&amp;lt;script src="https://js.hsforms.net/forms/embed/12345678.js" defer&amp;gt;&amp;lt;/script&amp;gt;
&amp;lt;div class="hs-form-frame" data-region="na1" data-form-id="5da9sdj76-47f8-412d-a98a-659874fv12" data-portal-id="12345678"&amp;gt;&amp;lt;/div&amp;gt;

&amp;lt;script&amp;gt;
// Function to handle form submission
function onHubSpotFormSubmit(event) {
    event.preventDefault(); // Prevent the default form submission if needed
    console.log("Form submitted!");
    // Add your custom code here
}

// Check if the form is loaded and then add the event listener
function attachHubSpotFormSubmitListener() {
    var formElement = document.querySelector('.hs-form-frame form');
    if (formElement) {
        formElement.addEventListener('submit', onHubSpotFormSubmit);
    } else {
        // Retry after a short delay if the form is not yet loaded
        setTimeout(attachHubSpotFormSubmitListener, 100);
    }
}

// Ensure the script runs after the page is fully loaded
document.addEventListener('DOMContentLoaded', function() {
    attachHubSpotFormSubmitListener();
});
&amp;lt;/script&amp;gt;
​&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 28 Aug 2024 13:11:05 GMT</pubDate>
      <guid>https://community.hubspot.com/t5/Lead-Capture-Tools/Onsubmit-function-in-multistep-beta-forms/m-p/1033360#M11916</guid>
      <dc:creator>Eric_Hoyer</dc:creator>
      <dc:date>2024-08-28T13:11:05Z</dc:date>
    </item>
    <item>
      <title>Re: Onsubmit function in multistep beta forms</title>
      <link>https://community.hubspot.com/t5/Lead-Capture-Tools/Onsubmit-function-in-multistep-beta-forms/m-p/1033955#M11917</link>
      <description>&lt;P&gt;The onsubmit function is still not firing. It doesn't fire even when I log all events on the page.&lt;/P&gt;</description>
      <pubDate>Thu, 29 Aug 2024 13:09:54 GMT</pubDate>
      <guid>https://community.hubspot.com/t5/Lead-Capture-Tools/Onsubmit-function-in-multistep-beta-forms/m-p/1033955#M11917</guid>
      <dc:creator>Mart999</dc:creator>
      <dc:date>2024-08-29T13:09:54Z</dc:date>
    </item>
    <item>
      <title>Re: Onsubmit function in multistep beta forms</title>
      <link>https://community.hubspot.com/t5/Lead-Capture-Tools/Onsubmit-function-in-multistep-beta-forms/m-p/1239488#M13503</link>
      <description>&lt;P&gt;Boo, no upvotes for an untested GPT solution!&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;HS added the ability to load the form as html (wrapped in '.hs-form-html' vs in an iframe (wrapped in '.hs-form-frame') &lt;A href="https://knowledge.hubspot.com/forms/set-up-and-style-your-form-on-an-external-site" target="_blank"&gt;https://knowledge.hubspot.com/forms/set-up-and-style-your-form-on-an-external-site&lt;/A&gt;&amp;nbsp;- if you check the "developer code" box, it'll reveal this bit of code that you can use to load the HTML version of your form. Annoyingly, this box does not stay checked.&amp;nbsp;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="amcintosh_0-1767840525052.png" style="width: 400px;"&gt;&lt;img src="https://community.hubspot.com/t5/image/serverpage/image-id/165397i72E42C13EE26228E/image-size/medium?v=v2&amp;amp;px=400" role="button" title="amcintosh_0-1767840525052.png" alt="amcintosh_0-1767840525052.png" /&gt;&lt;/span&gt;&lt;BR /&gt;&lt;BR /&gt;Then, you can add an event listener using the global form event listeners -&amp;nbsp;&lt;A href="https://developers.hubspot.com/docs/api-reference/global-form-events/guide" target="_blank"&gt;https://developers.hubspot.com/docs/api-reference/global-form-events/guide&lt;/A&gt;&lt;BR /&gt;&lt;BR /&gt;window.addEventListener('hs-form-event:on-submission:success', (event) =&amp;gt; {&lt;BR /&gt;&amp;nbsp;// Do whatever you need to do&lt;BR /&gt;})&lt;BR /&gt;&lt;BR /&gt;Didn't need to have this overwrite the default form on submit behavior, but I'm sure it's possible to do if you need to.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 08 Jan 2026 03:00:22 GMT</pubDate>
      <guid>https://community.hubspot.com/t5/Lead-Capture-Tools/Onsubmit-function-in-multistep-beta-forms/m-p/1239488#M13503</guid>
      <dc:creator>amcintosh</dc:creator>
      <dc:date>2026-01-08T03:00:22Z</dc:date>
    </item>
    <item>
      <title>Re: Onsubmit function in multistep beta forms</title>
      <link>https://community.hubspot.com/t5/Lead-Capture-Tools/Onsubmit-function-in-multistep-beta-forms/m-p/1242436#M13521</link>
      <description>&lt;P&gt;This &lt;STRONG&gt;100%&lt;/STRONG&gt; should be the only accepted solution.&amp;nbsp; No polling, no mutation observers.&amp;nbsp; The docs have official support for event listeners in the V4 method of form embeds.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 16 Jan 2026 18:35:49 GMT</pubDate>
      <guid>https://community.hubspot.com/t5/Lead-Capture-Tools/Onsubmit-function-in-multistep-beta-forms/m-p/1242436#M13521</guid>
      <dc:creator>squatchcreative</dc:creator>
      <dc:date>2026-01-16T18:35:49Z</dc:date>
    </item>
  </channel>
</rss>

