私はここまででフォームの検証を成功させてきました。フィールド、電子メールの検証、スパムのハニーポットが必要です。しかし、本当にフォームを提出しないと、私のクライアントの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>
電子メールフィールドを含むフォームの結果はすべて空白で、コード内に何かが正しくないか、ロボットがよりスマートになり、検証を回避する方法があることがわかります。 私のコードに基づいて、名字と姓が空白の場合、フォームは正しく通過しませんか? – Julesfrog
空白で私はchr(32)を意味しました。しかし、電子メールも空白だった場合、私の疑惑は間違っています。 –
あなたの入力Eugenに感謝します。 – Julesfrog