PHP code example of aryehraber / statamic-captcha

1. Go to this page and download the library: Download aryehraber/statamic-captcha 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/ */

    

aryehraber / statamic-captcha example snippets




return [
    'service' => 'Recaptcha', // options: Recaptcha / Hcaptcha / Turnstile / Altcha
    'sitekey' => env('CAPTCHA_SITEKEY', ''),
    'secret' => env('CAPTCHA_SECRET', ''),
    'forms' => [],
    'user_login' => false,
    'user_registration' => false,
    'disclaimer' => '',
    'invisible' => false,
    'hide_badge' => false,
    'enable_api_routes' => false,
    'custom_should_verify' => null,
];



return [
    'service' => 'Recaptcha', // options: Recaptcha / Hcaptcha / Turnstile / Altcha
    'sitekey' => 'YOUR_SITEKEY_HERE', // Or add to .env
    'secret' => 'YOUR_SECRET_HERE', // Or add to .env
    'forms' => ['contact', 'newsletter'],
    // ...
];



return [
    'forms' => 'all',
    // ...
];



return [
    // ...
    'custom_should_verify' => \App\Support\MyCustomShouldVerify::class,
];



namespace App\Support;

use AryehRaber\Captcha\Contracts\CustomShouldVerify;

class MyCustomShouldVerify implements CustomShouldVerify
{
    public function __invoke($event): ?bool
    {
        // bypass verification for authenticated users
        if (auth()->check()) {
            return false;
        }

        // bypass verification on dev environment
        if (app()->environment('dev')) {
            return false;
        }

        // bypass verification based on event form submission
        if ($event instanceof \Statamic\Events\FormSubmitted) {
            // return $event->submission;
        }

        // bypass verification based on login event
        if ($event instanceof \Illuminate\Auth\Events\Login) {
            // return $event->user;
        }

        // bypass verification based on user registration event
        if ($event instanceof \Statamic\Events\UserRegistering) {
            // return $event->user;
        }

        // bypass verification based on entry saving event
        if ($event instanceof \Statamic\Events\EntrySaving) {
            // return $event->entry;
        }
    }
}

 php please vendor:publish --tag=captcha-config

php please vendor:publish --tag="captcha-translations"