MailChimp JS Validation Isn't Working MailChimp JS Validation Isn't Working wordpress wordpress

MailChimp JS Validation Isn't Working


In effect the error is corrected if the script is moved to the footer of the page, but it is logical because the script calls a variable before it is created in the Dom, logically its status will always be undefined.

If you as in my case want to put the script in the header of the web, you will have to give a value to the url variable in case it is not available, and that value will have to be taken from the action field of the form, as simple as that.

if (typeof url == 'undefined') {url = "https://yoursite.us85.list-manage.com/subscribe/post?u=13s79c67xxb4c8ad2339ce34a&id=d1htsl3a46";}

The function would look like this:

getAjaxSubmitUrl: function () {var url = $ ("form # mc-embedded-subscribe-form"). attr ("action");if (typeof url == 'undefined') {url = "https://yoursite.us85.list-manage.com/subscribe/post?u=13s79c67xxb4c8ad2339ce34a&id=d1htsl3a46";}url = url.replace ("/ post? u =", "/ post-json? u =");url + = "& c =?";return url;},

I hope it helps!


In our case, the following code in the hosted file mc-validate.js was responsible:

/** *  Grab the list subscribe url from the form action and make it work for an ajax post. */getAjaxSubmitUrl: function() {    var url = $("form#mc-embedded-subscribe-form").attr("action");    url = url.replace("/post?u=", "/post-json?u=");    url += "&c=?";    return url;},

The line that starts var url = … is looking for a FORM with the ID mc-embedded-subscribe-form. If a form with this ID is missing from the page, the script fails. In OP's code it looks like this form exists, so I'm not 100% sure why the code was failing on OP's page. In our page, we had changed the form's ID, and that was the cause of the error.


Just like @thirdender below, the code in the hosted file mc-validate.js was responsible. And we DID correctly have the id placed the form.

getAjaxSubmitUrl: function() {  var url = $("form#mc-embedded-subscribe-form").attr("action");  url = url.replace("/post?u=", "/post-json?u=");  url += "&c=?";  return url;}, 

The fix, for us, was to load the script into the footer of the website.
It would not work correctly by loading it into the <head> section.

I hope this helps someone.