[英]google invisible recaptcha , wordpress, ajax, save data
我試圖弄清楚如何將Google Invisible reCaptcha集成到附加到submit.js(ajax)的自定義提交表單中。 感謝這個實施新的Invisible reCaptcha來自谷歌我正在使用成功的谷歌99%的網站隱形recaptcha。 我嘗試遵循相同的指南但是當我在調用submit.js(ajax)之前嘗試添加到listing.php中時,一切正常但如果用戶提交了一些錯誤(忘記了一些字段),則值不會像之前一樣保存。 這是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();
});
任何想法 ? 謝謝,如果你能給我一些提示,我會在一個完整的夢魘中:D
使用.js文件或.php文件中的代碼下方檢查google captcha值。 如果為空,則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>';
}
此代碼適用於PHP。 您可以在.js中檢查$ _POST值
我覺得它對你很有幫助。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.