简体   繁体   English

用户通过验证后,删除reCaptcha的HTML5自定义错误消息

[英]Remove HTML5 custom error message for reCaptcha after user passes validation

I am trying to build upon this answer: https://stackoverflow.com/a/37048027 我正在尝试基于以下答案: https : //stackoverflow.com/a/37048027

The answer worked but I wanted to put in a custom HTML5 validation error message so I expanded the javascript to this: 答案有效,但我想输入自定义HTML5验证错误消息,因此将javascript扩展为:

 window.onload = function() {
    var $recaptcha = document.querySelector('#g-recaptcha-response');
    if($recaptcha) {
        $recaptcha.setAttribute("required", "required");
        $recaptcha.setAttribute("oninvalid", "this.setCustomValidity('Please fill in the reCAPTCHA field.')");
        $recaptcha.setAttribute("oninput", "this.setCustomValidity('')");
    }
};

The issue is that if the validation error is shown once, it is always shown afterwards and never goes away. 问题是,如果仅显示一次验证错误,则始终在之后显示,并且永远不会消失。 I tried adding the oninput, onvalid and onchange but I can't seem to get the error message to go away after the initial showing. 我尝试添加oninput,onvalid和onchange,但是在最初显示之后,似乎无法使错误消息消失。

You can disable HTML5 form validation by adding novalidate to the form element according to this specification. 您可以根据规范通过将novalidate添加到form元素来禁用HTML5表单验证。

For example 例如

<form action="..." onsubmit="check_if_capcha_is_filled" novalidate>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM