gpt4 book ai didi

javascript - Google Recaptcha(联系人仍然发送通过)

转载 作者:行者123 更新时间:2023-11-30 16:07:19 27 4
gpt4 key购买 nike

我的联系页面有问题,非常感谢有人可以帮助我进行 google recaptcha 编码。

我已将所有脚本和 key 添加到我的 html 中。它显示在我的网站上,但即使我没有点击 recaptcha,我的联系页面仍然会显示。我知道是我的 java 脚本通过了 recaptcha。以下是 html 代码、javascript 和 php 代码。希望有人能告诉我哪里出了问题。

HTML代码:

<div class="col-md-6 col-md-6">
<h3 class="title">Contact Form</h3>
<p class="form-message"></p>
<div class="contact-form">
<!-- Form Begins -->
<form role="form" name="contactform" id="contactform" method="post" action="php/contact-form-recaptcha.php">
<div class="row">
<div class="col-md-6">
<!-- Field 1 -->
<div class="input-text form-group">
<input type="text" name="contact_name" class="input-name form-control"
placeholder="Full Name" />
</div>
</div>
<div class="col-md-6">
<!-- Field 2 -->
<div class="input-email form-group">
<input type="email" name="contact_email" class="input-email form-control"
placeholder="Email" />
</div>
</div>
</div>
<!-- Field 3 -->
<div class="input-email form-group">
<input type="text" name="contact_phone" class="input-phone form-control" placeholder="Phone" />
</div>
<!-- Field 4 -->
<div class="textarea-message form-group">
<textarea name="contact_message" class="textarea-message form-control" placeholder="Message"
rows="6"></textarea>
</div></DIV>
<!-- Captcha Box -->
<div class="g-recaptcha" data-sitekey="6************************************Z"></div>
<!-- Button -->
<button class="btn btn-default" type="submit">Send Now
<i class="icon-paper-plane"></i></button>
</form>
<!-- Form Ends -->
</div>

Javascript(如果所有字段都已填写,这是通过 recaptcha 的 javascript):

/* ---------------------    
Contact Form
/* --------------------- */
simplecontactForm: function(){
if ( $( "#contactform" ).length !== 0 ) {
$('#contactform').bootstrapValidator({
container: 'tooltip',
feedbackIcons: {
valid: 'fa fa-check',
warning: 'fa fa-user',
invalid: 'fa fa-times',
validating: 'fa fa-refresh'
},
fields: {
contact_name: {
validators: {
notEmpty: {
message: ''
}
}
},
contact_email: {
validators: {
notEmpty: {
message: ''
},
emailAddress: {
message: ''
},
regexp: {
regexp: '^[^@\\s]+@([^@\\s]+\\.)+[^@\\s]+$',
message: 'The value is not a valid email address'
}
}
},
contact_phone: {
validators: {
notEmpty: {
message: ''
}
}
},
contact_message: {
validators: {
notEmpty: {
message: ''
}
}
},
}
})
.on('success.form.bv', function(e) {
e.preventDefault();
var $form = $(e.target),
validator = $form.data('bootstrapValidator'),
submitButton = validator.getSubmitButton();
var form_data = $('#contactform').serialize();
$.ajax({
type: "POST",
dataType: 'json',
url: "../php/contact-form-recaptcha.php",
data: form_data,
success: function(msg){
$('.form-message').html(msg.data);
$('.form-message').show();
submitButton.removeAttr("disabled");
resetForm($('#contactform'));
},
error: function(msg){}
});
return false;
});
}
function resetForm($form) {

$form.find(
'input:text, input:password, input, input:file, select, textarea'
)
.val('');

$form.find('input:radio, input:checkbox')
.removeAttr('checked')
.removeAttr('selected');
$form.find('button[type=submit]')
.attr("disabled", "disabled");

}
},

PHP (contact-form-recaptcha.php):

<?php
if(isset($_POST['submit']) && !empty($_POST['submit'])):
if(isset($_POST['g-recaptcha-response']) && !empty($_POST['g-recaptcha-response'])):
//your site secret key
$secret = '6*****************************u';
//get verify response data
$verifyResponse = file_get_contents('https://www.google.com/recaptcha/api/siteverify?secret='.$secret.'&response='.$_POST['g-recaptcha-response']);
$responseData = json_decode($verifyResponse);
if($responseData->success):
//contact form submission code
$to_email = "testing@testing.com"; // email address to which the form data will be sent
$subject = "Contact Request"; // subject of the email that is sent
$thanks_page = "index.html"; // path to the thank you page following successful form submission
$contact_page = "index.html"; // path to the HTML contact page where the form appears

$nam = strip_tags($_POST["contact_name"]);
$ema = strip_tags($_POST["contact_email"]);
$pho = strip_tags($_POST["contact_phone"]);
$com = strip_tags($_POST["contact_message"]);

// Always set content-type when sending HTML email
$headers = "MIME-Version: 1.0" . "\r\n";
$headers .= "Content-type:text/html;charset=UTF-8" . "\r\n";
// More headers
$headers .= 'From:'.$nam.' <'.$ema.'>' . "\r\n";
//send email
$email_body =
"<strong>From: </strong>" . $nam . "<br />
<strong>Email: </strong>" . $ema . "<br />
<strong>Phone: </strong>" . $pho . "<br />
<strong>Message: </strong>" . $com;

$succMsg = 'Your contact request have submitted successfully.';
else:
$errMsg = 'Robot verification failed, please try again.';
endif;
else:
$errMsg = 'Please click on the reCAPTCHA box.';
endif;
else:
$errMsg = '';
$succMsg = '';
endif;
?>

请帮助我...谢谢一百万...

最佳答案

如果您想检查用户是否点击了我不是机器人复选框,您可以使用 reCaptcha API 提供的 .getResponse() 函数。

如果用户没有验证自己,它将返回一个空字符串,如下所示:

if(grecaptcha.getResponse() == "")
alert("You can't proceed!");
else
alert("Thank you");

如果用户已经验证了自己,响应将是一个很长的字符串。

有关 API 的更多信息,请访问此页面:reCaptcha Javascript API

关于javascript - Google Recaptcha(联系人仍然发送通过),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36831879/

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