Formvalidation.io-无法读取null的属性“ classList”

时间:2018-11-07 09:20:57

标签: javascript html css invisible-recaptcha formvalidation.io

使用formvalidation.io时,控制台始终出现错误。

enter image description here

我不知道此错误的原因是什么。即使使用backendVerificationURL,我仍然在某些网站上收到垃圾邮件。我正在使用Invisible ReCaptcha(https://formvalidation.io/guide/plugins/recaptcha/

我的HTML表单:

                                <form id="contact" method="post" action="/vendor/contact-form.php">
                                <div class="card-body">
                                    <div class="row">
                                        <div class="col-md-6">
                                            <div class="form-group label-floating is-empty">
                                                <label class="bmd-label-floating">Naam</label>
                                                <input type="text" name="naam" id="naam" class="form-control">
                                                <span class="material-input"></span>
                                            </div>
                                        </div>
                                        <div class="col-md-6">
                                            <div class="form-group label-floating is-empty">
                                                <label class="bmd-label-floating">Telefoonnummer</label>
                                                <input type="text" name="telefoon" id="telefoon" class="form-control">
                                                <span class="material-input"></span>
                                            </div>
                                        </div>
                                    </div>
                                    <div class="form-group label-floating is-empty">
                                        <label class="bmd-label-floating">Mailadres</label>
                                        <input type="email" name="email" id="email" class="form-control">
                                        <span class="material-input"></span>
                                    </div>
                                    <div class="form-group label-floating is-empty">
                                        <label for="bericht" class="bmd-label-floating">Uw bericht</label>
                                        <textarea name="bericht" class="form-control" id="bericht" rows="6"></textarea>
                                        <span class="material-input"></span>
                                    </div>
                                </div>
                                <div class="card-footer justify-content-between">
                                    <div class="form-check">
                                        <!-- De captcha container -->
                                        <div id="captchaContainer"></div>
                                    </div>
                                    <button type="submit" class="btn btn-brown">Aanvragen</button>
                                </div>
                            </form>

这是我的验证脚本(validation-contact.js):

document.addEventListener('DOMContentLoaded', function(e) {
FormValidation.formValidation(
    document.getElementById('contact'),
    {
    fields: {

        naam: {
            validators: {
                notEmpty: {
                    message: 'Vul alstublieft uw naam in'
                }
            }
        },
        telefoon: {
            validators: {
                phone: {
                    country: 'NL',
                    message: 'U heeft een ongeldig telefoonnummer ingevuld'
                },
                notEmpty: {
                    message: 'Vul alstublieft uw telefoonnummer in'
                }
            }
        },
        email: {
            validators: {
                notEmpty: {
                    message: 'Vul alstublieft uw emailadres in'
                },
                emailAddress: {
                    message: 'U heeft een ongeldig emailadres ingevuld'
                }
            }
        },
    },
    plugins: {
        trigger: new FormValidation.plugins.Trigger(),
        bootstrap: new FormValidation.plugins.Bootstrap(),
        submitButton: new FormValidation.plugins.SubmitButton(),
        defaultSubmit: new FormValidation.plugins.DefaultSubmit(),
        icon: new FormValidation.plugins.Icon({
            valid: 'fa fa-check',
            invalid: 'fa fa-times',
            validating: 'fa fa-refresh',
        }),
        recaptcha: new FormValidation.plugins.Recaptcha({
            element: 'captchaContainer',
            message: 'The captcha is not valid or expired',
            // Replace with the site key provided by Google
            siteKey: 'MYSITEKEY',
            badge: 'bottomleft',
            theme: 'light',
            size: 'invisible',
            backendVerificationUrl: '/vendor/verification-url.php',
        }),
    },
})

});

编辑: 在页面的顶部,我有:

    <link rel="stylesheet" href="/assets/css/fontawesome-all.css" />
<link rel="stylesheet" href="https://unpkg.com/tachyons@4.10.0/css/tachyons.min.css">
<link rel="stylesheet" href="/vendor/formvalidation/dist/css/formValidation.min.css">

并在页脚中:

    <script src="https://cdnjs.cloudflare.com/ajax/libs/es6-shim/0.35.3/es6-shim.min.js"></script>    
<script src="/vendor/formvalidation/dist/js/FormValidation.min.js"></script>
<script src="/vendor/formvalidation/dist/js/plugins/Recaptcha.min.js"></script>
<script src="/vendor/formvalidation/dist/js/plugins/Tachyons.min.js"></script>
<script src="/vendor/formvalidation/dist/js/plugins/Bootstrap.min.js"></script>

编辑:编辑:

页面底部如下所示: enter image description here

2 个答案:

答案 0 :(得分:1)

<div class="form-row">
<div class="form-group form-check">
<input type="checkbox" class="form-check-input">
</div>
</div>

1。我们必须将form-group包括在表单的所有字段中。 2.如果我们有复选框,请相对于表单组类包括表单检查类。然后将form-check-input类添加到input标签。 3.如果您正在使用reCapture复选框,请参考此链接(https://formvalidation.io/guide/plugins/recaptcha/

如果要标识错误字段。请一一删除表单验证中的字段,然后检查是否收到classList错误。如果我们在某个特定领域遇到了该错误。如上所述,您只需修改该文件即可。

答案 1 :(得分:0)

我对FormValidaiton.io的1.3版有一个非常相似的问题。为了它的价值,并在有帮助的情况下,我通过在form-check DIV中嵌套任何form-group DIV元素来解决了我的问题。

<div class="form-group"><div class="form-check"></div></div>

一种可行的替代方法是使用rowSelector选项-如此处的示例所示。

https://formvalidation.io/guide/examples/validating-checkbox-list-placed-multiple-columns/

相关问题