MailChimp JS验证不起作用 [英] MailChimp JS Validation Isn't Working

查看:59
本文介绍了MailChimp JS验证不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用MailChimp的一种嵌入式表格,复制到wordpress弹出窗口生成器中.问题是MailChimp表单中的JS导致错误,因此表单的验证不起作用.这是错误:

I am using one of MailChimp's embedded forms, copied into a wordpress popup builder. The issue is the JS in MailChimp's form is causing an error, so the validation of the form doesn't work. Here is the error:

Uncaught TypeError: Cannot read property 'replace' of undefined
// This error occurs in the file: mc-validate.js:198

这是完整的表单代码:

    <!-- Begin MailChimp Signup Form -->
<link href="//cdn-images.mailchimp.com/embedcode/classic-081711.css" rel="stylesheet" type="text/css">
<style type="text/css">
    #mc_embed_signup{background:#fff; clear:left; font:14px Helvetica,Arial,sans-serif;  width:500px;}
    /* Add your own MailChimp form style overrides in your site stylesheet or in this style block.
       We recommend moving this block and the preceding CSS link to the HEAD of your HTML file. */
</style>
<div id="mc_embed_signup">
<form action="" method="post" id="mc-embedded-subscribe-form" name="mc-embedded-subscribe-form" class="validate" target="_blank" novalidate>
    <div id="mc_embed_signup_scroll">
    <h2>Subscribe to our mailing list</h2>
<div class="indicates-required"><span class="asterisk">*</span> indicates required</div>
<div class="mc-field-group">
    <label for="mce-EMAIL">Email Address  <span class="asterisk">*</span>
</label>
    <input type="email" value="" name="EMAIL" class="required email" id="mce-EMAIL">
</div>
    <div id="mce-responses" class="clear">
        <div class="response" id="mce-error-response" style="display:none"></div>
        <div class="response" id="mce-success-response" style="display:none"></div>
    </div>    <!-- real people should not fill this in and expect good things - do not remove this or risk form bot signups-->
    <div style="position: absolute; left: -5000px;"><input type="text" name="b_c86e002570c2075b57186bd84_ee52af27a3" tabindex="-1" value=""></div>
    <div class="clear"><input type="submit" value="Subscribe" name="subscribe" id="mc-embedded-subscribe" class="button"></div>
    </div>
</form>
</div>
<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[0]='EMAIL';ftypes[0]='email';}(jQuery));var $mcj = jQuery.noConflict(true);</script>
<!--End mc_embed_signup-->

我用于弹出窗口的插件是确实智能弹出

The plugin I'm using for the popup is Indeed Smart PopUp

推荐答案

实际上,如果将脚本移到页面的页脚,则可以更正错误,但这是合乎逻辑的,因为脚本在创建变量之前先调用了变量从逻辑上说,Dom的状态始终是不确定的.

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.

如果在我的情况下,如果您希望将脚本放置在Web标头中,则必须为url变量提供一个值,以防它不可用,并且该值必须从操作中获取表单的字段,就这么简单.

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&amp;id=d1htsl3a46";}

函数看起来像这样:

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&amp;id=d1htsl3a46";}url = url.replace ("/ post? u =", "/ post-json? u =");url + = "& c =?";return url;},

希望对您有帮助!

这篇关于MailChimp JS验证不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆