gpt4 book ai didi

ajax - 使用AJAX的g验证码响应

转载 作者:行者123 更新时间:2023-12-04 13:26:37 29 4
gpt4 key购买 nike

我有一个联系表,它通过ajax请求将其信息发送到php脚本。现在,我想实现Google的“我不是机器人”验证码。

问题是,我不知道如何用ajax传输g-recaptcha-response。
如何验证它并将结果发送到send_contactrequest_process.php?

<div class="kontakt-container">
<form class="kontakt-form" id="kontakt-form" method="post">
<input type="text" name="firstname" id="contact-form-firstname" placeholder="Vorname (erforderlich)" class="kontakt-form-input" minlength="2" required="required" data-msg="Du musst dieses Feld ausfüllen">
<input type="text" name="lastname" id="contact-form-lastname" placeholder="Nachname (erforderlich)" class="kontakt-form-input" minlength="2" required="required" data-msg="Du musst dieses Feld ausfüllen">
<input type="tel" name="telephone" id="contact-form-telephone" placeholder="Telefonnummer" class="kontakt-form-input">
<input type="email" name="email" id="contact-form-email" placeholder="E-Mail (erforderlich)" class="kontakt-form-input" minlength="10" required="required" data-msg="Diese Email-Adresse ist ungültig">
<textarea class="kontakt-form-message" id="contact-form-message" required="required" data-msg="Was möchtest du uns mitteilen?"></textarea>
<div class="g-recaptcha" data-sitekey="MY KEY"></div>
<div class="kontakt-form-submit" id="kontakt-form-submit">senden</div>
</form>
<p class="kontakt-form-success-message">Vielen Dank für Deine Nachricht.</p>
</div>

  if($("#kontakt-form").valid()){

var firstname = $('#contact-form-firstname').val(); //Validierung der Form-Daten
var lastname = $('#contact-form-lastname').val();
var email = $('#contact-form-email').val();
var telephone = $('#contact-form-telephone').val();
var message = $('#contact-form-message').val();

$.ajax({ //AJAX request
type: "POST",
url: "../../../include/process/send_contactrequest_process.php",
data: {firstname: firstname, lastname: lastname, email:email, telephone:telephone, message:message},
success: function () {
$('.kontakt-form-success-message').css( "display","inline" );
},
});
}

最佳答案

只是调用此函数grecaptcha.getResponse();像这样 :

if($("#kontakt-form").valid()){

var firstname = $('#contact-form-firstname').val(); //Validierung der Form-Daten
var lastname = $('#contact-form-lastname').val();
var email = $('#contact-form-email').val();
var telephone = $('#contact-form-telephone').val();
var message = $('#contact-form-message').val();

$.ajax({ //AJAX request
type: "POST",
url: "../../../include/process/send_contactrequest_process.php",
data: {
firstname: firstname,
lastname: lastname,
email:email,
telephone:telephone,
message:message,
recaptcha:grecaptcha.getResponse()
},
success: function () {
$('.kontakt-form-success-message').css( "display","inline" );
},
});
}

关于ajax - 使用AJAX的g验证码响应,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32285716/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com