尝试过滤掉在线表单中的垃圾邮件。我有一个带输入的隐藏div。我们的想法是,如果某些内容进入该字段,该表单会将用户标识为机器人并拒绝提交。在尝试实施此方法后,机器人仍在通过。我不是很熟悉javascript(或垃圾邮件过滤,就此而言) - 这就是我正在使用的内容:
html(在表单中):
<form action="#" method='post' id='vsurvey' name='defer'>
<div id="hp-div">
If you see this, leave this form field blank
and invest in CSS support.
<input type="text" name="question_20579" value="" />
</div>
<input type="submit" value="Submit Request" />
</form>
的CSS:
#hp-div { display: none }
JS:
<script type="text/javascript" charset="ISO-8859-1" src="//ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script>
<script type="text/javascript" charset="ISO-8859-1" src="http://ajax.aspnetcdn.com/ajax/jquery.validate/1.9/jquery.validate.min.js"></script>
<script type="text/javascript">
if(!String.IsNullOrEmpty(Request.Form["question_20579"]))
IgnoreComment();
</script>
<![if !IE]>
<script type="text/javascript">
$(document).ready(function(){
$("#vsurvey").validate({
invalidHandler: function(form, validator) {
var errors = validator.numberOfInvalids();
if (errors) {
var message = errors == 1
? 'Oops! You missed 1 field. It has been highlighted'
: 'Oops! You missed ' + errors + ' fields. They have been highlighted below';
$("div.alert span").html(message);
$("div.alert").show();
} else {
$("div.alert").hide();
}
},
errorPlacement: function(error, element) {
return true;
}
})
});
</script>
<![endif]>
答案 0 :(得分:13)
在我看来,蜜罐应包含以下所有内容:
例如:
<div class="input-field">
Please leave this blank
<input type="text" name="contact" value="" />
</div>
<div class="text-field">
Please do not change this field
<input type="text" name="email" value="your@email.com" />
</div>
使用CSS隐藏第一个字段:
.input-field { display: none; }
使用jQuery,隐藏第二个字段:
$('.text-field').hide();
// or
$('.text-field').addClass('hide');
然后用PHP进行一些非常简单的检查:
if($_POST['contact'] == '' && $_POST['email'] == 'your@email.com') {
// Not a bot
}