Skip to content

Instantly share code, notes, and snippets.

@macariojames
Last active March 25, 2022 13:16
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save macariojames/19fdb5c169a4aa38549944f671aba871 to your computer and use it in GitHub Desktop.
Save macariojames/19fdb5c169a4aa38549944f671aba871 to your computer and use it in GitHub Desktop.
MailChimp hide form on successful submit and thank you message; jQuery
// Add a surrounding <div> for all the ish don't want to keep once submission is successful
<script type='text/javascript' src='//s3.amazonaws.com/downloads.mailchimp.com/js/mc-validate.js'></script>
<script type='text/javascript'>(function($) {window.fnames = new Array(); window.ftypes = new Array();fnames[1]='FNAME';ftypes[1]='text';fnames[0]='EMAIL';ftypes[0]='email';}(jQuery));
//var $mcj = jQuery.noConflict(true);
</script>
<script>
$(function(){
//$("#mcm_hide_on_submit").hide();
$(".button").on("click", function(){
if ( $('#mce-success-response:visible') ) {
console.log('Successfully signed up');
$('#mc_hide_on_submit').hide();
$('#mce-success-response').css('margin', "0");
}
});
});
</script>
@danieliser
Copy link

Better version:

<script>
	var mc1Submitted = false;
	jQuery('#mc-embedded-subscribe-form').on('submit reset', function (event) {
		console.log(event);
		 if ("submit" === event.type) {
		 	mc1Submitted = true;
		 } else if ( "reset" === event.type && mc1Submitted ) {
		 	console.log('success');
		 }
	});
</script>

@macariojames
Copy link
Author

macariojames commented Jan 29, 2020

Thanks @danieliser. I'm no longer using MailChimp, but looking over your code real quick, this is looks like a good alternative.

Side note: your Content Control and Popup WP plugins look awesome -- going to test them out on one of my development sites!

Better version:

<script>
	var mc1Submitted = false;
	jQuery('#mc-embedded-subscribe-form').on('submit reset', function (event) {
		console.log(event);
		 if ("submit" === event.type) {
		 	mc1Submitted = true;
		 } else if ( "reset" === event.type && mc1Submitted ) {
		 	console.log('success');
		 }
	});
</script>

@danieliser
Copy link

@macariojames - Let us know what you think, be sure to check out Ahoy & User Menus as well.

@tristanisginger
Copy link

tristanisginger commented Mar 25, 2022

Vanilla version - slightly different but you get the idea

<script>
    var mc1Submitted = false;
    var signUpForm = document.getElementById('mc-embedded-subscribe-form');
    signUpForm.addEventListener('reset', function (event) {
        var signUpForm2 = document.getElementById('mc-embedded-subscribe-form');
	signUpForm2.style.display = "none";
        var signUpForm = document.getElementById('mce-success-response');
        document.getElementById('mc_embed_signup').append(signUpForm)
    });

</script>

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment