Run a javascript funcion on contact form submit

Hello!

I’m a developer working for an agency, we received a landing page that was built with Webflow, and I need to make a small change to it: When the form is succesfully submitted, it should run a javascript function.

This function would trigger all leads necessary for our social media, such as Facebook lead, google analytics leds, etc

I have access to the .HTML code through FTP. The website is this: http://www.minhacasanovolar.com.br/

Can someone please shed me a light?
Thanks!

3 Likes

Hi Lucas,

I have a similar problem and I am looking for a solution. I was wondering if you found something that helped you progress?

Thanks in advance!

Hey @DanielVerbaan!

I’m not sure if you’re looking for something more, but if you just want to run a function on your form submit you should:

First assign an “id” to your form block element. You can do that by selecting your form block element and on the right hand side of the designer under the gear icon there is an “id” input.

Second you can use the following embedded custom code to set an event listener on the form submit. (Make sure to use the id that you chose).

function logSubmit(event) {
  event.preventDefault();

[Do your javascript stuff here]

}

const form = document.getElementById('form');
form.addEventListener('submit', logSubmit);

If you need more information on how submit event listeners work checkout https://developer.mozilla.org/en-US/docs/Web/API/HTMLFormElement/submit_event

1 Like