简体   繁体   English

google invisible recaptcha,wordpress,ajax,保存数据

[英]google invisible recaptcha , wordpress, ajax, save data

Im trying to figure out how to integrate Google Invisible reCaptcha to a custom submit form attached to submit.js (ajax). 我试图弄清楚如何将Google Invisible reCaptcha集成到附加到submit.js(ajax)的自定义提交表单中。 Thanks to this Implement the new Invisible reCaptcha from Google i'm using with success Google invisible recaptcha on 99% of the site. 感谢这个实施新的Invisible reCaptcha来自谷歌我正在使用成功的谷歌99%的网站隐形recaptcha。 I try to follow the same guide but when i try to add into listing.php before the call to submit.js (ajax), everything works but if the user commit some errors (forget some fields), values are not saved like before. 我尝试遵循相同的指南但是当我在调用submit.js(ajax)之前尝试添加到listing.php中时,一切正常但如果用户提交了一些错误(忘记了一些字段),则值不会像之前一样保存。 Here is the submit.js (ajax) 这是submit.js(ajax)

jQuery('#lp-submit-form').submit(function(e){
$this = jQuery(this);
$this.find('.preview-section .fa-angle-right').removeClass('fa-angle-right');
$this.find('.preview-section .fa').addClass('fa-spinner fa-spin');
var fd = new FormData(this);

fd.append('action', 'listingpro_submit_listing_ajax');
jQuery.ajax({
    type: 'POST',
    url: ajax_listingpro_submit_object.ajaxurl,
    data:fd,
    contentType: false,
    processData: false,

    success: function(res){


        var resp = jQuery.parseJSON(res);
        if(resp.response==="fail"){
            jQuery.each(resp.status, function (k, v) {

                if(k==="postTitle"){
                    jQuery("input:text[name='postTitle']").addClass('error-msg');   
                }
                else if(k==="gAddress"){
                    jQuery("input:text[name='gAddress']").addClass('error-msg');
                }
                else if(k==="category"){
                    jQuery("#inputCategory_chosen").find('a.chosen-single').addClass('error-msg');
                    jQuery("#inputCategory").next('.select2-container').find('.selection').find('.select2-selection--single').addClass('error-msg');
                }
                else if(k==="location"){
                    jQuery("#inputCity_chosen").find('a.chosen-single').addClass('error-msg');
                    jQuery("#inputCity").next('.select2-container').find('.selection').find('.select2-selection--single').addClass('error-msg');
                }
                else if(k==="postContent"){
                    jQuery("textarea[name='postContent']").addClass('error-msg');
                }
                else if(k==="email"){
                    jQuery("input#inputEmail").addClass('error-msg');
                }

            });
            var errorrmsg = jQuery("input[name='errorrmsg']").val();
            $this.find('.preview-section .fa-spinner').removeClass('fa-spinner fa-spin');
            $this.find('.preview-section .fa').addClass('fa-times');
            $this.find('.preview-section').find('.error_box').text(errorrmsg).show();
        }
        else if(resp.response==="failure"){
            jQuery("input#inputEmail").addClass('error-msg');
            jQuery("input#inputEmail").after(resp.status);
            $this.find('.preview-section .fa-spinner').removeClass('fa-spinner fa-spin');
            $this.find('.preview-section .fa').addClass('fa-angle-right');
        }
        else if(resp.response==="success"){
            $this.find('.preview-section .fa-spinner').removeClass('fa-times');
            $this.find('.preview-section .fa-spinner').removeClass('fa-spinner fa-spin');               
            $this.find('.preview-section .fa').addClass('fa-check');
            var redURL = resp.status;
            function redirectPageNow(){
                    window.location.href= redURL;
            }
            setTimeout(redirectPageNow, 1000);

        }


    },
    error: function(request, error){
        alert(error);
    }
});

e.preventDefault();

 }); 

Any idea ? 任何想法 ? Thanks if you can give me some Tips, im in a complete Nightmare :D 谢谢,如果你能给我一些提示,我会在一个完整的梦魇中:D

Check google captcha value by use below code in in .js file or .php file. 使用.js文件或.php文件中的代码下方检查google captcha值。 If empty the google captcha give the alert box or error message. 如果为空,则Google验证码会显示警告框或错误消息。

if(isset($_POST['g-recaptcha-response']))
{
    $captcha=$_POST['g-recaptcha-response'];
}
if(!$captcha)
{
  echo '<p>Please verify that you are not a robot.</p>';
}

This code is for PHP. 此代码适用于PHP。 You can check $_POST value in .js 您可以在.js中检查$ _POST值
I think it helps you. 我觉得它对你很有帮助。

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

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