I want to push a datalayer with the form data. To do so I am trying to access form data after submission as explained in this solution but is not working:
It looks like the event which you can get the values on is not 'onFormSubmitted' but 'onFormSubmit', see capture below :
You see how two messages get sent with the postMessage() function from the iframe ?
Both are tied to an event, and the code you mention tries to get the value of the email key, but it's not present in the 'onFormSubmitted' object.
Change it to 'onFormSubmit' to get the values submitted with the form.
Then you have two solutions : - if you want to make one code apply to all your forms, whatever their composition may be, you can loop on the data array and return only the email. - if it's just for one form, you can make that simpler by locating the index of the email value and change your code by :
It looks like the event which you can get the values on is not 'onFormSubmitted' but 'onFormSubmit', see capture below :
You see how two messages get sent with the postMessage() function from the iframe ?
Both are tied to an event, and the code you mention tries to get the value of the email key, but it's not present in the 'onFormSubmitted' object.
Change it to 'onFormSubmit' to get the values submitted with the form.
Then you have two solutions : - if you want to make one code apply to all your forms, whatever their composition may be, you can loop on the data array and return only the email. - if it's just for one form, you can make that simpler by locating the index of the email value and change your code by :
Rather embarassing novice question here...but how did you get the event data to show up in console like that...it'd be very useful for me to see that. My orgnization is beginning to ask for some development based on the responses of the forms, which I can do, but the HubSpot documentation recommends not using onFormSubmit for redirects and to use onFormSubmitted, but input field values are not available in the onFormSubmitted function. This topic seems to answer some of my questions but I'd love to be able to see the event data the way you showed in console.
Hi, Ludwig i cant understand how to get success form submit evant and also how to get email after submit i write this, but i think it`s not a good practice
window.addEventListener('message', event => { if (event.data['meetingBookSucceeded'] && event.data['meetingBookSucceeded'] === true) { var email = event.data['meetingsPayload']['bookingResponse']['postResponse']['contact']['email']; if (!email) { return; } alert(email) } });