Last active
August 9, 2018 08:11
-
-
Save khalidahmada/732dad6db92a893502f1addb10c90497 to your computer and use it in GitHub Desktop.
Contact Form 7 - Javascript snippet to prevent the multiples submits forms
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(function($){ | |
var wpcf7Elm = document.querySelector( '.wpcf7' ); | |
function handlerEventProcess(event){ | |
var hiddensubmit = $(wpcf7Elm).find('form').find('.js-hide-bloc'); | |
if(hiddensubmit.length){ | |
hiddensubmit.removeClass('js-hide-bloc'); | |
hiddensubmit.css('display','initial'); | |
} | |
} | |
if(wpcf7Elm){ | |
$(wpcf7Elm).find('form').on('submit' , function(ev){ | |
// If the form is already active then prevent submit | |
if($(this).find('.js-hide-bloc').length){ | |
ev.preventDefault(); | |
ev.stopPropagation(); | |
return false; | |
} | |
// Add custom class to hide button | |
var hiddensubmit = $('.ajax-loader.is-active').prev('input[type=submit]'); | |
hiddensubmit.addClass('js-hide-bloc'); | |
hiddensubmit.css('display','none'); | |
}); | |
// Contact Form 7 Events | |
wpcf7Elm.addEventListener( 'wpcf7submit',handlerEventProcess, false ); | |
wpcf7Elm.addEventListener( 'wpcf7invalid',handlerEventProcess, false ); | |
wpcf7Elm.addEventListener( 'wpcf7spam',handlerEventProcess, false ); | |
wpcf7Elm.addEventListener( 'wpcf7mailsent',handlerEventProcess, false ); | |
wpcf7Elm.addEventListener( 'wpcf7mailfailed',handlerEventProcess, false ); | |
} | |
})(jQuery); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment