これまでのところ、以下のフォーム検証を正常に使用しています。必須フィールド、電子メール検証、およびスパム用のハニーポットがあります。しかし、私のクライアントの 1 人は、実際にはフォームをまったく送信してはならないのに、空白のフォーム結果を取得しています。だから多分私は明らかなことを見ていない。とてもシンプルなコードだと思います。誰かが簡単に見て、私が何かを逃したかどうかを教えてもらえますか?
別の話として、スパム ロボットはハニーポットよりも賢くなっているのでしょうか?
これはJSです:
<script>
function verify() {
var themessage = "You are required to complete the following fields: ";
var x=document.form.email.value
var atpos=x.indexOf("@");
var dotpos=x.lastIndexOf(".");
if (document.form.address.value!="") {
themessage = "You are not human! No form for you!";
}
if (document.form.first_name.value=="") {
themessage = themessage + " - First Name";
}
if (document.form.last_name.value=="") {
themessage = themessage + " - Last Name";
}
if (document.form.email.value=="") {
themessage = themessage + " - E-mail";
}
if (atpos<1 || dotpos<atpos+2 || dotpos+2>=x.length) {
themessage = "You need to enter a valid email address";
}
//alert if fields are empty and cancel form submit
if (themessage == "You are required to complete the following fields: ") {
document.form.submit();
}
else {
alert(themessage);
return false;
}
}
</script>
そしてHTML:
<form name="form" method="post" action="output.php">
<div id="input">
<div id="field">First Name:</div>
<input name="first_name" type="text" id="first_name">
</div>
<div id="input">
<div id="field">Last Name:</div>
<input name="last_name" type="text" id="last_name">
</div>
<div id="input">
<div id="field">Email:</div>
<input name="email" type="text" id="email">
</div>
<div class="input address"><!-- This is the Honeypot -->
<div id="field">Address:</div>
<input name="address" type="text" id="address">
</div>
<div id="input">
<div id="field">Phone:</div>
<input name="phone" type="text" id="phone">
</div>
<div id="input">
<div id="field3">Comments:</div>
<textarea name="comments" id="comments"></textarea>
</div>
<input type="button" value="Submit" onclick="verify();">
</form>