Last active
March 25, 2022 13:16
-
-
Save macariojames/19fdb5c169a4aa38549944f671aba871 to your computer and use it in GitHub Desktop.
MailChimp hide form on successful submit and thank you message; jQuery
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
// 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> |
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>
@macariojames - Let us know what you think, be sure to check out Ahoy & User Menus as well.
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
Better version: