• Resolved davidwong3937

    (@davidwong3937)


    Hi, I need to add some javascript event at the submission button. So <button ….> becomes <button onclick=”some_event_here” ….>

    Can I know how can I do that?

    Thank you!

Viewing 6 replies - 1 through 6 (of 6 total)
  • Plugin Support Williams – WPMU DEV Support

    (@wpmudev-support8)

    Hi @davidwong3937

    I hope you’re well today!

    You can use this code:

    add_action(
    	'wp_footer',
    	function() {
    		if ( ! class_exists( 'Forminator' ) ) {
    			return;
    		}
    		?>
    
    		<script>
    			(function($){
    				$(function(){
    					function wpmudev_fm_avoid_duplicate_submissions( _forms ){
    						if( _forms.length ){
    							let _parent_button = null,
    								_timeout = null;
    							setTimeout(function(){
    								_forms.on('click', '.forminator-button-submit', function(){
    									
    									alert('something');
    									
    									
    								});
    							}, 200);
    						}
    					}
    
    					wpmudev_fm_avoid_duplicate_submissions( $('.forminator-custom-form') );
    					// Support ajax.
    					$(document).on('after.load.forminator', function(e, _form_id){
    						wpmudev_fm_avoid_duplicate_submissions( $('#forminator-module-'+ _form_id) );
    					});
    				});
    			})(window.jQuery)
    		</script>
    		<?php
    	},
    	21
    );

    You’d need to add it to your site in your own plugin or via MU plugin or to your theme’s “functions.php” file.

    Your own code that should be executed upon click, should go instead this line:

    alert('something');

    Best regards,
    Adam

    Thread Starter davidwong3937

    (@davidwong3937)

    Thank you for your reply.

    Maybe I should ask this as well, I guess it can be common.

    Is there anywhere to set up the Google ads tracking codes for the forminator submit button? Any shortcut that I can insert the code of gtag_report_conversion, which conventionally was set up with onClick function?

    the forminator has Ajax enabled and not redirecting to any success page.

    By the way, Forminator is really one of the best plugins I have ever used! Really good job!

    Plugin Support Williams – WPMU DEV Support

    (@wpmudev-support8)

    Hi @davidwong3937

    If you can integrate these tracking codes via GTag then it should be doable with a little help of our other free plugin – Beehive.

    It features support for both Google Tag Manager and Forminator so
    – you set your codes with GTM
    – add GTM container ID to Beehive on “Beehive -> Google Tag Manager -> Account” page
    – and enable integration with Forminator on “Beehive -> Google Tag Manager -> Settings” page in “Integrations” tab.

    This will cause Forminator to send some data/events to Google Tag Manager through Beehive. You would need to use that data with your scripts/tags but that’s in Google Tag Manager directly.

    Take a look here please:

    https://wpmudev.com/docs/wpmu-dev-plugins/beehive/#integrations

    Best regards,
    Adam

    Thread Starter davidwong3937

    (@davidwong3937)

    thank you. Google tag manager already in use. Beehive also installed and connected with the GTM.

    So just to confirm, with Beehive and GTM set up, I can track conversion trigger by the Forminator form submission with Ajax enabled?

    Once user clicks “submit” and form sent out successfully, and Beehive is able to record this kind of conversion and send back to GTM?

    Thank you

    Plugin Support Patrick – WPMU DEV Support

    (@wpmudevsupport12)

    Hi @davidwong3937

    I hope you are doing well.

    You will be able to enable this integration in Beehive yes, it should work fine out of the box with Ajax’s request.

    The full doc is found at https://wpmudev.com/docs/wpmu-dev-plugins/beehive/#integrations

    Best Regards
    Patrick Freitas

    Plugin Support Amin – WPMU DEV Support

    (@wpmudev-support2)

    Hello @davidwong3937 ,

    We haven’t heard from you for some time now, so it looks like you don’t need our assistance anymore.

    Feel free to re-open this ticket if needed.

    Kind regards
    Kasia

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘How to add onclick event on the submit button’ is closed to new replies.