PHP code example of coderflex / filament-turnstile

1. Go to this page and download the library: Download coderflex/filament-turnstile 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/ */

    

coderflex / filament-turnstile example snippets


use Coderflex\FilamentTurnstile\Forms\Components\Turnstile;

Turnstile::make('captcha')
    ->theme('auto') // accepts light, dark, auto
    ->language('en-US') // see below
    ->size('normal'), // accepts normal, compact

protected function onValidationError(ValidationException $exception): void
{
    $this->dispatch('reset-captcha');

    // Perform additional actions as necessary (e.g., display error messages)
}

$this->dispatch('reset-captcha');

protected function authenticate(): void
{
    // Perform authentication logic
    // ...

    if (! Auth::attempt($this->data)) {
        $this->throwFailureValidationException(
            [
                'email' => 'Invalid email or password.',
            ]
        );
    }

    // Redirect to success page or perform other actions
}

namespace App\Filament\Pages\Auth;

use Coderflex\FilamentTurnstile\Forms\Components\Turnstile;
use Filament\Pages\Auth\Login as AuthLogin;
use Filament\Schemas\Schema;

class Login extends AuthLogin
{
    public function form(Schema $form): Schema
    {
        return $form
            ->schema([
                $this->getEmailFormComponent(),
                $this->getPasswordFormComponent(),
                $this->getRememberFormComponent(),
                Turnstile::make('captcha')
                    ->label('Captcha')
                    ->theme('auto'),
            ]);
    }

    // if you want to reset the captcha in case of validation error
    protected function throwFailureValidationException(): never
    {
        $this->dispatch('reset-captcha');

        parent::throwFailureValidationException();
    }
}

namespace App\Providers\Filament;

use App\Filament\Auth\Login;
use Filament\Panel;
use Filament\PanelProvider;

class AdminPanelProvider extends PanelProvider
{
    public function panel(Panel $panel): Panel
    {
        return $panel
            ->default()
            ->id('admin')
            ->path('admin')
            ->login(Login::class); // override the login page class.
            ...
    }
}