谷歌验证码(联系人仍然发送)
Google Recaptcha (Contact Still Send Through)
我的联系页面有问题,非常感谢有人可以帮助我进行谷歌验证码编码。
我已经将所有脚本和密钥添加到我的 html 中。它显示在我的网站上,但即使我没有点击验证码,我的联系页面仍然通过。我知道是我的 java 脚本正在通过验证码。下面是html代码,javascript和php编码。希望有人能让我知道出了什么问题。
网页代码:
<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
相关文章:
- 正在验证8个真/假复选框或复选框中的2个
- 在验证和发送邮件后更改联系人表单的 html
- jquery.validator和一个页面上的两个联系人表单将在提交时验证空表单
- 谷歌验证码(联系人仍然发送)
- 我正在验证一个联系人表单.我是不是过滤太多了
- 滚动至联系人表格7中的已验证字段(wordpress)
- 如何使用JS清理联系人表单后删除HTML5表单验证
- 验证HTML联系人表单
- 使用PHP、JS和Ajax验证联系人表单
- 如何使用JavaScript验证联系人表单
- 使用javascript验证联系人表单
- 使用jquery和php验证联系人表单
- PHP/JS联系人表单-验证
- 联系人字段的Javascript验证
- 联系人表单的Javascript验证
- 没有打开联系人页面的验证码
- Google联系人API错误:通过脚本加载请求超时.可能的原因:源URL不正确;提要需要身份验证
- 联系人表单默认值验证
- 在AngularJS中带服务器端验证的联系人表单
- Html5联系人表单- javascript和php验证的问题