1. <?php //post the form fields from below
  2. $name = $_POST['name'];
  3. $machine = $_POST['machine'];
  4. if ($machine != "")
  5. {
  6. exit(); //if a spambot filled out the "machine"
  7. //field, we don't proceed
  8. }
  9. else
  10. {
  11. //validate the name and do stuff with it
  12. }
  13. ?>
  14.  
  15. <!DOCTYPE html>
  16. <html>
  17. <head>
  18. <title>Test Form</title>
  19. <style>
  20. /* hide the "machine" field */
  21. .machine { display: none; }
  22. </style>
  23. </head>
  24. <body>
  25. <form method="post" action="">
  26. <input name="name" />
  27. <!-- below field is hidden with css -->
  28. <input name="machine" class="machine" />
  29. <!-- edit - show a warning (also hidden) to users with CSS disabled -->
  30. <label for="machine" class="machine">If you are a human, don't fill out this field!</label>
  31. <input type="submit" />
  32. </form>
  33. </body>
  34. </html>
OK, the idea here is that spambots will fill out all fields in the form. So we hide one of the fields with CSS (so users don't see it) and if it's filled out, we don't allow the submission to complete. This isn't my idea but I don't remember exactly where I found it. In my experience, it's been quite effective at preventing automated spam. Any thoughts, pros, cons?