根据需要设置reCaptcha字段 [英] Set reCaptcha field as required

查看:658
本文介绍了根据需要设置reCaptcha字段的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我将新的reCaptcha与 jQuery Validate 插件一起使用.验证插件可以很好地与我的表单一起使用,但是不幸的是,它与reCaptcha不能一起使用.我尝试使其在下面运行:

I use the new reCaptcha with the jQuery Validate plugin. The validation plugin works nice with my form but unfortunately it didn't work with reCaptcha. My attempt to make it work below:

HTML:

<div class="g-recaptcha" name="recaptcha" id="recaptcha" data-sitekey="XXXXX"></div> 

JavaScript:

Javascript:

 recaptcha: {
    required: true
      }    

但是没有用.有谁知道如何解决这一问题.我只需要默认的必填字段错误消息.

but it didn't worked. Does anyone know how to fix this. I simply need the default This field is required error message.

推荐答案

所以我设法使其起作用.唯一的问题是用户完成reCaptcha后,此字段必填消息不会很快消失.我正在使用模糊,抠像和聚焦来检测用户输入并删除错误消息.

So I managed to make it worked. The only problem is after user completing reCaptcha, the message This field is required does not quickly dissapear. I'm using blur, keydown and focusout to detect user input and remove the error message.

JS:

$("#myForm").bind('blur keydown focusout', function(){ 

        var dataArray = $("#myForm").serializeArray(),
        dataObj = {};
        console.dir(dataArray); //require firebug
        //console.log(dataArray);

        $(dataArray).each(function(i, field){
          dataObj[field.name] = field.value;
        });

        var recaptcha = (dataObj['g-recaptcha-response']);

        if(recaptcha != "") {
                $( "#temp" ).remove();
        }       
    });

    $( ".register" ).click(function() {

        var dataArray = $("#myForm").serializeArray(),
            dataObj = {};
            console.dir(dataArray); //require firebug
            //console.log(dataArray);

        $(dataArray).each(function(i, field){
          dataObj[field.name] = field.value;
        });

        var recaptcha = (dataObj['g-recaptcha-response']);

        $( "#temp" ).remove();

            if(recaptcha == "") {
                $("#recaptcha").append('<label id="temp" style="color:red;line-height:normal;font-size: small;">This field is required.</label>');
            }

    });             

});

HTML:

<div class="g-recaptcha" name="recaptcha" id="recaptcha" data-sitekey="XXXXXXXXXXXXXXXXXXXXXXXXX"></div>   

这篇关于根据需要设置reCaptcha字段的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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