Testing MailerLite Form

Are you ready to offer a free Advanced Reader Copy?  Why reinvent the wheel.  Click below to download my Instructional and Cheat Sheet

Pictures-of-Templates-ARC-Verbiage-Signup-Reviews

Sign Up for ARC Instructional

Don't want to recreate the wheel?  Sign up below to get my Advanced Reader Copy Verbiage Template!

Email Name Please be patient 🙂

Thank you for sign up!

var selectedLanguage = ""; var validationMessages = messages["en"]; if(selectedLanguage) { validationMessages = messages[selectedLanguage]; } window.addEventListener("load", function () { var form_container = document.querySelector(`#mailerlite-form_3[data-temp-id="64e2121f3b886"] form`); let submitButton = form_container.querySelector('.mailerlite-subscribe-submit'); submitButton.disabled = true; fetch('https://readfirstchapter.com/wp-admin...', { method: 'POST', headers:{ 'Content-Type': 'application/x-www-form-urlencoded', }, body: new URLSearchParams({ "action" : "ml_create_nonce", "ml_nonce" : form_container.querySelector("input[name='ml_nonce']").value }) }) .then((response) => response.json()) .then((json) => { if(json.success) { form_container.querySelector("input[name='ml_nonce']").value = json.data.ml_nonce; submitButton.disabled = false; } }) .catch((error) => { console.error('Error:', error); }); form_container.addEventListener('submit', (e) => { e.preventDefault(); let data = new URLSearchParams(new FormData(form_container)).toString(); let validationError = false; Array.from(form_container.elements).forEach((input) => { if(input.type !== 'hidden') { if(input.required) { if(input.value == '') { validationError = true; if(input.nextElementSibling == null) { let error = document.createElement("span"); error.className = 'mailerlite-form-error'; error.textContent = validationMessages.required; input.after(error); } } } } }); if(validationError) { return false; } fade.out(form_container.querySelector('.mailerlite-subscribe-button-container'), () => { fade.in(form_container.querySelector('.mailerlite-form-loader')); }); fetch('https://readfirstchapter.com/wp-admin...', { method: 'POST', headers:{ 'Content-Type': 'application/x-www-form-urlencoded', }, body: data }) .then((response) => { fade.out(form_container.querySelector('.mailerlite-form-inputs'), () => { fade.in(form_container.querySelector('.mailerlite-form-response')); }); }) .catch((error) => { console.error('Error:', error); }); }); }, false); var fade = { out: function(el, fn = false) { var fadeOutEffect = setInterval(function () { if (!el.style.opacity) { el.style.opacity = 1; } if (el.style.opacity > 0) { el.style.opacity -= 0.1; } else { el.style.display = 'none'; clearInterval(fadeOutEffect); } }, 50); if( typeof (fn) == 'function') { fn(); } }, in: function(el) { var fadeInEffect = setInterval(function () { if (!el.style.opacity) { el.style.opacity = 0; } if (el.style.opacity < 1) { el.style.opacity = Number(el.style.opacity) + 0.1; } else { el.style.display = 'block'; clearInterval(fadeInEffect); } }, 50); } }

 

 •  0 comments  •  flag
Share on Twitter
Published on August 19, 2023 16:24
No comments have been added yet.