PHP code example of niirrty / niirrty.forms.security

1. Go to this page and download the library: Download niirrty/niirrty.forms.security library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

niirrty / niirrty.forms.security example snippets



use \Niirrty\Forms\Security\DynamicFormField;

$dynamicField = new DynamicFormField();

if ( $dynamicField->isValidRequest() )
{
   // The field is permitted successful => handle the real form data
}
else
{
   // No Request => show the form with the 



use \Niirrty\Forms\Security\FormTimer;

// Init the form timer
$formTimer = new FormTimer(
   true,                     // Use session?
   'FormTimer.NameOfMyForm'  // Session var name
);

// $isPostRequest is an imaginary value that must be replaced bei you're code to check if an POST request of
// you're form exists
if ( $isPostRequest )
{
   if ( ! $formTimer->isValidRequest() )
   {
      // no valid Timer request => Ignore this request and show the form
   }
   else
   {
      // Handle the valid request
   }
}



use \Niirrty\Forms\Security\HoneyPot;

$honeypot = new HoneyPot( 'fieldName', \INPUT_POST );

if ( $honeypot->isValidRequest() )
{
   // The honeypot field is permitted successful => handle the real form data
}
else
{
   // No Request => show the form with the at do not support CSS. e.g. "do not fill this field"
   echo '&lt;label class="inv1s1ble"&glt;&amp;#80;l&amp;#101;a&amp;#115;e&amp;#32;d&amp;#111; &amp;#110;o&amp;#116; &amp;#102;i&amp;#108;l&amp;#32;t&amp;#104;i&amp;#115; &amp;#102;i&amp;#101;l&amp;#100;&lt;/label&gt;';
   // Example of output the