# Duplicate forms on same page using V2 API

**URL:** <https://community.hubspot.com/t/duplicate-forms-on-same-page-using-v2-api/95312>\
**Category:** APIs & Integrations\
**Tags:** developer-tools, forms\
**Created:** [December 4, 2023, 1:25pm UTC](https://community.hubspot.com/t/duplicate-forms-on-same-page-using-v2-api/95312 "2023-12-04T13:25:24Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![ADeConinck3](https://avatars.discourse-cdn.com/v4/letter/a/919ad9/32.png) [@ADeConinck3](https://community.hubspot.com/u/ADeConinck3)\
**Post date:** [December 4, 2023, 1:25pm UTC](https://community.hubspot.com/t/duplicate-forms-on-same-page-using-v2-api/95312/1 "2023-12-04T13:25:24Z")

</div>

I generate 2 or more duplicate forms onto my page inside modals using the v2 script. I have noticed the onFormSubmitted I attach to the form instances is called incorrectly on a different instance of the form about 75% of the time instead of the correct instance. Is there a solution to this? Does the onFormSubmitted use the instanceId at all or only the formId?

```lia-code-sample
<script charset="utf-8" type="text/javascript" src="//js-eu1.hsforms.net/forms/embed/v2.js">

...

this.formInstance = hbspt.forms.create({
 portalId: this.portalId,
 formId: this.formId,
 target: `#...`,
 onFormReady: (e) => this.setupInputs(e),
 onFormSubmit: (e) => this.onSubmit(e),
 onFormSubmitted: (e) => this.onFormSuccess(e),
 })

```

Kind regards

Arnout

---

<div class="post-metadata">

**Author:** ![Jaycee\_Lewis](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/jaycee_lewis/32/61352_2.png) [@Jaycee\_Lewis](https://community.hubspot.com/u/Jaycee_Lewis)\
**Post date:** [December 6, 2023, 6:05pm UTC](https://community.hubspot.com/t/duplicate-forms-on-same-page-using-v2-api/95312/2 "2023-12-06T18:05:01Z")

</div>

Hi, @ADeConinck3 👋 Thanks for your question. I’d like to invite some of our community members to the conversation – @Teun [@Mike\_Eastwood](https://community.hubspot.com/t5/user/viewprofilepage/user-id/9259), how would tackle this? Or do you have any other ways you might approach a project like this?

Thank you! — Jaycee

---

<div class="post-metadata">

**Author:** ![FTrands](https://avatars.discourse-cdn.com/v4/letter/f/f08c70/32.png) [@FTrands](https://community.hubspot.com/u/FTrands)\
**Post date:** [December 11, 2023, 8:32am UTC](https://community.hubspot.com/t/duplicate-forms-on-same-page-using-v2-api/95312/3 "2023-12-11T08:32:17Z")

</div>

When dealing with multiple duplicate forms on the same page using the HubSpot V2 API script, you’ve observed that the event onFormSubmitted is sometimes called incorrectly on a different instance of the form. To address this, you can implement a solution by ensuring that each form instance has a unique identifier.

The HubSpot V2 script doesn’t expose a direct instanceId that you can use for identification. However, you can manually assign a unique identifier to each form instance by creating a custom property or using the formId and then associating it with the onFormSubmitted event. This way, you can track which instance triggered the event accurately.

this.formInstance = hbspt.forms.create({ portalId: this.portalId, formId: this.formId, target: `#…`, instanceId: “uniqueIdentifier1”, // Assign a unique identifier to each instance onFormReady: (e) =\> this.setupInputs(e), onFormSubmit: (e) =\> this.onSubmit(e), onFormSubmitted: (e) =\> this.onFormSuccess(e, “uniqueIdentifier1”), // Pass the unique identifier to the event handler });

Adjust the instanceId for each form instance accordingly. Then, in your onFormSuccess function, you can check the identifier to determine which form instance triggered the event:

onFormSuccess: (e, instanceId) =\> { if (instanceId === “uniqueIdentifier1”) { // Handle form success for the first instance } else if (instanceId === “uniqueIdentifier2”) { // Handle form success for the second instance } // Add more conditions as needed for additional instances }

By introducing unique identifiers for each form instance, you can reliably track and handle the onFormSubmitted events associated with specific forms, minimizing the chance of incorrect event calls.
