Form submission from landing page

I am trying to post data received from the form to my backend. However, the submit code is not firing. I have added it to both the header and footer sections and can get the console.log to show up. Furthermore, if I paste this code into the browser console, the submit code fires.

<script>
$(function() {

console.log('The DOM is ready!');
$("form[data-form-id='formID'").submit(function (event) {
let data = JSON.stringify($(this).serializeArray());
console.log('Form Submittion');
$.ajax({
url: "redacted",
type: "POST",
data: data,
contentType: "text/plain; charset=utf-8",
dataType: "text"
})

});
});
</script>

Hi @scottj425

Have a play with HubSpot’s onFormSubmit Method:

This should make your life much easier.

Have fun

Mike