无法使验证码工作 - 甚至可以提交错误的答案

时间:2014-03-20 17:58:36

标签: javascript html forms captcha

我有一个网站,我在几乎每一页都设计了一个联系表格。这个表格最近受到了很多垃圾邮件的攻击,所以我想添加一个验证码 - 但谷歌的免费reCaptcha糟透了,所以我想用一个更好的。

我发现了这个并希望使用它:

http://jsfiddle.net/M5rvh/23/

HTML

<form action="php/contactus.php" method="post" name="contact_form" id="contact_form">
  <h2>Contact Us</h2>
  <br>
    <h5>Full Name *</h5>
      <input type="text" name="name" class="text" placeholder="John Doe" onfocus="if (this.value==this.defaultValue) this.value='';" onblur="if (this.value=='') this.value=this.defaultValue;" required />

    <h5>Association Name *</h5>
      <input type="text" name="association" class="text" placeholder="HOA Name" onfocus="if (this.value==this.defaultValue) this.value='';" onblur="if (this.value=='') this.value=this.defaultValue;" required />

    <h5>Email Address *</h5>
      <input type="text" name="email" class="text" placeholder="youremail@email.com" onfocus="if (this.value==this.defaultValue) this.value='';" onblur="if (this.value=='') this.value=this.defaultValue;" required />

    <h5>Phone Number *</h5>
      <input type="text" name="phone" class="text" placeholder="555-555-5555" onfocus="if (this.value==this.defaultValue) this.value='';" onblur="if (this.value=='') this.value=this.defaultValue;" required />

    <h5>Message *</h5>
      <textarea name="message" rows="6" onfocus="if (this.value==this.defaultValue) this.value='';" onblur="if (this.value=='') this.value=this.defaultValue;" required>Our HOA Concerns Are...</textarea>

    <h5 class="captchaclass">Captcha *</h5>
      <div class="submit">
        <input type="image" src="images/button-submit_s1.jpg" alt="Submit" value="Submit" />
      </div>
</form>

JAVASCRIPT

<script type="text/javascript">
$(function(){

var mathenticate = {
    bounds: {
        lower: 5,
        upper: 50
    },
    first: 0,
    second: 0,
    generate: function()
    {
        this.first = Math.floor(Math.random() * this.bounds.lower) + 1;
        this.second = Math.floor(Math.random() * this.bounds.upper) + 1;
    },
    show: function()
    {
        return this.first + ' + ' + this.second;
    },
    solve: function()
    {
        return this.first + this.second;
    }
};
mathenticate.generate();

var $auth = $('<input type="text" name="auth" required />');
$auth
    .attr('placeholder', mathenticate.show())
    .insertAfter('h5[class="captchaclass"]');

$('#contact_form').on('submit', function(e){
    e.preventDefault();
    if( $auth.val() != mathenticate.solve() )
    {
        alert('wrong answer!');
    }
});

})
</script>

我试图让这个在这个页面上工作(http://wmdouglas.org/apex.html),但无论我尝试什么,它都无法正常工作。验证码显示并且需要在提交之前完成,但我可以输入错误的答案,然后它仍然会转到我的成功页面。

发生了什么事?

0 个答案:

没有答案
相关问题