# How to avoid hubspot tracking code to listen form submit event

**URL:** <https://community.hubspot.com/t/how-to-avoid-hubspot-tracking-code-to-listen-form-submit-event/46278>\
**Category:** APIs & Integrations\
**Tags:** events, forms, contacts\
**Created:** [November 1, 2021, 5:26pm UTC](https://community.hubspot.com/t/how-to-avoid-hubspot-tracking-code-to-listen-form-submit-event/46278 "2021-11-01T17:26:35Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![joaobrosin](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/joaobrosin/32/105116_2.png) [@joaobrosin](https://community.hubspot.com/u/joaobrosin)\
**Post date:** [November 1, 2021, 5:26pm UTC](https://community.hubspot.com/t/how-to-avoid-hubspot-tracking-code-to-listen-form-submit-event/46278/1 "2021-11-01T17:26:35Z")

</div>

Hello,  
We have a non-HubSpot form on our website page. Below this form, we have our HubSpot tracking code that reads the form input values and sends them to our Hubspot database of contacts when the submit button is clicked.  
Ok, this is what was supposed to happen. But we have a problem.  
Every time the user clicks on submit button, the form inputs are read and sent to our HubSpot account, even if the form is not fulfilled.  
On our page, we have some scripts that send error messages to the user when the user forgets to fill some input.  
However, even if the input is not filled, the tracking code still works and sends just part of the data.  
Is there any way to avoid default submit listening on the tracking code, and just allow the submission listener when the inputs are all filled?  
Thx for your help.

---

<div class="post-metadata">

**Author:** ![mfs\_cea\_au](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/mfs_cea_au/32/35608_2.png) [@mfs\_cea\_au](https://community.hubspot.com/u/mfs_cea_au)\
**Post date:** [November 1, 2021, 8:07pm UTC](https://community.hubspot.com/t/how-to-avoid-hubspot-tracking-code-to-listen-form-submit-event/46278/2 "2021-11-01T20:07:06Z")

</div>

@joaobrosin - I’m new to HS but I did notice this behavior in the documentation. That is, the behavior is expected, and HS even has a “warning.” Read under the section: Before you get started

> **[Use non-HubSpot forms](https://knowledge.hubspot.com/forms/use-non-hubspot-forms)**
>
> Learn how to set up and use non-HubSpot forms to collect submissions on your website's existing forms in HubSpot.

What would I do? I’d use JS to disable the submit button until all your other validation checks out.

---

<div class="post-metadata">

**Author:** ![joaobrosin](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/joaobrosin/32/105116_2.png) [@joaobrosin](https://community.hubspot.com/u/joaobrosin)\
**Post date:** [November 5, 2021, 11:55am UTC](https://community.hubspot.com/t/how-to-avoid-hubspot-tracking-code-to-listen-form-submit-event/46278/3 "2021-11-05T11:55:24Z")

</div>

How could I do it with javascript?  
I have been trying to use “event.preventDefault()” on the form submit listener, but it doesn’t work =\

---

<div class="post-metadata">

**Author:** ![dennisedson](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/dennisedson/32/28044_2.png) [@dennisedson](https://community.hubspot.com/u/dennisedson)\
**Post date:** [November 5, 2021, 2:23pm UTC](https://community.hubspot.com/t/how-to-avoid-hubspot-tracking-code-to-listen-form-submit-event/46278/4 "2021-11-05T14:23:55Z")

</div>

@joaobrosin , might be worth looking into the[forms api](https://legacydocs.hubspot.com/docs/methods/forms/submit_form).

So you would basically turn off the non HubSpot forms which is referenced in that doc that [@mfs\_cea\_au](https://community.hubspot.com/t5/user/viewprofilepage/user-id/259250) provided then when you are ready to actually submit the data, trigger a post to the forms submit endpoint

---

<div class="post-metadata">

**Author:** ![mfs\_cea\_au](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/mfs_cea_au/32/35608_2.png) [@mfs\_cea\_au](https://community.hubspot.com/u/mfs_cea_au)\
**Post date:** [November 8, 2021, 7:08pm UTC](https://community.hubspot.com/t/how-to-avoid-hubspot-tracking-code-to-listen-form-submit-event/46278/5 "2021-11-08T19:08:55Z")

</div>

@joaobrosin - See if this helps.  
[https://codesource.io/how-to-disable-button-in-javascript/](https://codesource.io/how-to-disable-button-in-javascript/)

You’re not preventing the click per se, there is an property for disabled. Use that until you’re sure all your validation has passed.

---

<div class="post-metadata">

**Author:** ![joaobrosin](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/joaobrosin/32/105116_2.png) [@joaobrosin](https://community.hubspot.com/u/joaobrosin)\
**Post date:** [November 9, 2021, 5:59pm UTC](https://community.hubspot.com/t/how-to-avoid-hubspot-tracking-code-to-listen-form-submit-event/46278/6 "2021-11-09T17:59:44Z")

</div>

I will disable the button. Good tip [@mfs\_cea\_au](https://community.hubspot.com/t5/user/viewprofilepage/user-id/259250)

Thx!

---

<div class="post-metadata">

**Author:** ![mfs\_cea\_au](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/mfs_cea_au/32/35608_2.png) [@mfs\_cea\_au](https://community.hubspot.com/u/mfs_cea_au)\
**Post date:** [November 9, 2021, 6:22pm UTC](https://community.hubspot.com/t/how-to-avoid-hubspot-tracking-code-to-listen-form-submit-event/46278/7 "2021-11-09T18:22:53Z")

</div>

@joaobrosin - One more tip…having done this myself…  
In my JS I have an array of the expected fields as well. More or less to mitigate someone inspecting the form and mucking around with it. Mind you, they can do the same with the JS but again, I just want to slow them down or at least get them to move on sooner rather than later.

I’m not JS Genius, but having a look at this (for a WordPress plugin I tossed together) might help you.  
[https://gitlab.com/WPezPlugins/wpez-hubspot-newsletter-form-ajax/-/blob/main/App/assets/dist/js/wpez-hsnf-main.min.js](https://gitlab.com/WPezPlugins/wpez-hubspot-newsletter-form-ajax/-/blob/main/App/assets/dist/js/wpez-hsnf-main.min.js)

Note: There’s a JSON object that contains a lot of the actual values / settings so you’ll have to use your imagination a bit.
