Currently there are three events associated with Form Block submission:
submit-form event is triggered before form submission.
submit-form-success event is triggered after successful form submission.
submit-form-failure event is triggered after unsuccessful form submission.
<script>
window.addEventListener('submit-form-form1', (e) => {
// e.detail is an object with form field names and values
console.log('form submit', e.detail);
// form submit { "Full Name": "Softr", "Email": "info@softr.io" }
});
window.addEventListener('submit-form-success-form1', (e) => {
// e.detail is an object with form field names and values
console.log('form submit success', e.detail);
// form submit success { "Full Name": "Softr", "Email": "info@softr.io" }
});
window.addEventListener('submit-form-failure-form1', (e) => {
console.log('form submit failure', e.detail);
// form submit failure 'Email field is required.'
});
</script>
Does this support form blocks with names that include a hyphen? For example, if the block was called “form-1” in Softr Studio, would that work and if so what should the syntax be?
I will be able to share a code for signup block tomorrow. Signup block is still to be updated by us to work with the above code. but I can help with old approach. Can you share a link ?
hi @artur thanks for your help here. What is the best way to catch a click on a list element (when not using the action buttons for which the React version of the solution seems to be this one: Action Buttons - Update Records event listeners)?
Hi @artur - Should this script work on pages that use the “Signup with side image” content block? The form I’m using doesn’t appear to have an ID or class I can use: https://app.coverdoc.ai/sign-up
I’m trying to use Google Tag Manager to fire an event in GA4 when a user signs up via the Softr form. I’d like to use dataLayer.push for the “submit-form” event but the script doesn’t work for me when I use a custom code block in Softr on https://app.coverdoc.ai/sign-up
@artur I have a custom code that listens to different forms on different pages in the footer custom code. the code is meant to show a custom loading screen when a form is submitted and refresh the parent page when the form submission is successful, it works on the dev environment(app clone) but it doesn’t work in prod(user-visible) the code looks like this below:
For your use case, few things:
You point, in your script, to loading-screen, but in your html it is loading-screen-n (at least one of them). Would this come from there?
The event listener for a block should be nested in another event listener, to avoid bugs.
@matthieu_chateau ok I tried adding the code at the page level, but then I feel it’s a selector thing because when i tried console logging something when the form is submitted it doesn’t show up in the console
here is a copy of my code