0

I'm using simple honeypot

my HTML

<input type="text" name="mail" id="mail">

my CSS

#mail{display:none;}

my PHP

if(isset($_POST["mail"])){
    $honeycomb_passed = "No";
} else {
    $honeycomb_passed = "Yes"; 
}

When I submit the form always outputs No. To my understanding it should output yes, right? Where is the problem?

Thanks

Selsta
  • 17
  • 2
  • 5

2 Answers2

0

Just because the field is hidden in CSS doesn't mean it isn't send to the server. If you don't want the email value to be sent to the server - try to user something like:

$('input[name=email]').remove();

to remove the element from the dom

be sure to wrap in:

$().ready(function(){});

If you're not using jQuery let me know!

Bas Kuis
  • 748
  • 1
  • 7
  • 20
0

You're doing it wrong.

A working honeypot

HTML

<form>
 <input type="text" name="mail" id="mail">
 <input type="submit">
</form>
<style>
 #mail{display:none;}
</style>

PHP

if($_POST && $_POST["mail"] != ""){
        die("Sorry, no robots");
}

How does it work

You have a hidden field inside your form. Typically, a robot will attempt to fill any form field available with data in the hope that it will not get rejected. Once it submits that form, your script will detect the input and die. If a human was filling it out, they would not see the hidden input (type=text style=display:none) and leave it empty. Thus the php would allow the submit to go ahead.

If you PHP script dies as soon as it detects the honeypot field, then you are saving yourself cpu cycles (because there is no need to reply reasonably to a robot).

For more information on honeypot, see this question: How do I add Honey pot fields to my forms?

Community
  • 1
  • 1
Jason
  • 15,064
  • 15
  • 65
  • 105