0

これまでのところ、以下のフォーム検証を正常に使用しています。必須フィールド、電子メール検証、およびスパム用のハニーポットがあります。しかし、私のクライアントの 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>
4

2 に答える 2

0

(電子メール以外の) フィールドに空白を入力すると、空のように見えるフォーム結果が生成されます。

于 2011-12-29T15:44:08.217 に答える
0

おそらく、フォーム データのクライアント側の検証のみを使用していますが、これは悪いことです。

ボットは JavaScript を実行しないため、verify関数を無視し、純粋な HTML で記述されたフォームをそのまま送信します。

一般に、セキュリティ上の理由と、ユーザーがブラウザーの設定で JavaScript を無効にしている可能性があるため、常にサーバー側の検証を優先する必要があります。

JavaScript でこれらの種類の検証を行うことは、使いやすさを向上させるためのオプション機能であるべきですが、セキュリティ機能 (「ハニーポット」など) を実装することは決してありません。

于 2011-12-29T16:20:21.597 に答える