Javascript Webhooks not firing

I am using WPcode to add a javascript snippet to a page. But I’m not able to get the gform_form_saving_action_save_begin to fire. I am looking for suggestion or hints as to why. Code below:

const event_name = 'save_begin';
gform.addAction( 'gform_form_saving_action_' + event_name , function( ) {
    alert('submit clicked');
	console.log('do something')
}, 10, 2 );

I believe the code you’ve shared seems to be correct, but it’s difficult to determine the exact issue without more information.

To resolve the problem, I suggest you try this code instead and let me know if it works for you:

jQuery(document).ready(function($) {
    const event_name = 'save_begin';
    gform.addAction( 'gform_form_saving_action_' + event_name , function( ) {
        alert('submit clicked');
        console.log('do something')
    }, 10, 2 );
});

This code will wait for the page to load before attaching the event listener. Let me know if you have any further questions or issues!

Thanks you for the help. Unfortunately that did not work. Jquery wasn’t loaded when the script ran, so I tried using a DOMcontentLoaded listener. But neither worked. Here is my latest attempt (This doesn’t work either) This should attach the ‘save_completed’ event listener after the DOM is loaded and the form rendered.

function addSubmitListener(event) {
	console.info('DOMContentLoaded event fired')
	jQuery(document).on('gform_post_render', function() {
		console.info('jQuery gform_post_render fired')
		const event_name = 'save_completed';
		gform.addAction( 'gform_form_saving_action_' + event_name , function( ) {
			console.log('save_completed event fired')
			analytics.identify(email,
			{
				name: 'jo tester',
				email: 'jotest@example.com'
			})
		}, 10,2 );
		console.log('gform.addAction save_completed event added');
	});
	console.log('jQuery gform_post_render event listener attached');
}

window.addEventListener('DOMContentLoaded', addSubmitListener(event));

and the output presented in the console on load:


(index):519 DOMContentLoaded event fired
(index):533 jQuery gform_post_render event listener attached
(index):521 jQuery gform_post_render fired
(index):531 gform.addAction save_completed event added

It appears that there is not a method to capture the submit event on the front end. The ‘save_completed’ is for when the form is created and saved. It is not for when the form is in use.

I will have to capture the submit on the backend using PHP.

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.