View on GitHub

honeypot

This PHP library is used to manage honeypots in HTML forms. It will create the input form and do the necessary checks.

honeypot

This PHP library is used to manage honeypots in HTML forms. It will create the input form and do the necessary checks.

Installation

Go to you project root directory and use composer using this command

composer require dominiquevienne/honeypot

Then create your application bootstrap using this kind of code

<?php
require __DIR__ . '/vendor/autoload.php';

$oForm  = new Dominiquevienne\Honeypot\Form();
echo $oForm->inputs();

Manual installation

$oForm = new Dominiquevienne\Honeypot\Form(); echo $oForm->inputs();

### Laravel
Using honeypot in Laravel is as simple as a

composer require dominiquevienne/honeypot

and add the following lines in your class
```php
<?php
use \Dominiquevienne\Honeypot\Form;

class yourController {
  public function show() {
    /** some code of yours */
    $oForm  = new Form();
    return $oForm->inputs();
  }
}

Drupal 8

First of all, go to your root directory of your Drupal 8 project and type

composer require dominiquevienne/honeypot

In the Form controller (where you build your form), add

use Dominiquevienne\Honeypot\Form;

in order to gain access to Honeypot Form constructor.

Instantiate your form using the drupalForm config array key set to TRUE

Checks are done in the validate function using standard functions.

How it works

Once the package is installed the honeypot consists in enabling two steps

Form rendering

Where you will trigger Form::timeCheck() which will store date-time of the Form rendering and trigger Form::honeypotInput() used to return the honeypot form element.

Any of those two options are mandatory.

<?php
$oForm          = new Dominiquevienne\Honeypot\Form();
$oForm->timeCheck();
$honeypotInputs = $oForm->inputs();
?>
<html>
<?php 
// All your HTML code before your form
?>
<form action="yourLandingPage.php" method="post">
<?php
// The standard fields of your form
echo $honeypotInputs;
?>
<input type="submit"/>
</html>

Be aware that you’ll need to hide the honeypot field. To do that, you’ll have three solutions