mewebstudio / captcha

Captcha for Laravel 5/6/7/8/9/10/11
MIT License
2.45k stars 452 forks source link

Captcha Value always gives invalid value #282

Open aeq-dev opened 7 months ago

aeq-dev commented 7 months ago

Hello guys, I'm trying to set the captcha on a form using livewire v3, I'm able to generate the image and refresh it, but every time I set the correct value, captcha gives me an invalid value. Please anyone has used it with livewire V3 ? Thanks

spam-n-eggs commented 5 months ago

@aeq-dev Take a look at how I implemented it in the Dominion Solutions Captcha plugin for Filament - I'm using Filament, but it's all on top of Livewire: https://github.com/dominion-solutions/filament-captcha. The key is properly entangling the state of the form: https://github.com/dominion-solutions/filament-captcha/blob/main/resources/views/form/components/captcha.blade.php. If you look at the top of the file you'll see:

<x-dynamic-component :component="$getFieldWrapperView()" :field="$field" :inline-label-vertical-alignment="\Filament\Support\Enums\VerticalAlignment::Center">
    <div x-data="{ state: $wire.$entangle('{{ $getStatePath() }}').defer }">

This is all the "stuff" I'm using to bind the state of the field for validation.

Then in the actual form component I'm using:

public function form(Form $form): Form
{
    return $form->schema([
        Captcha::make('captcha')
            ->rules(['captcha'])
            ->required()
            ->validationMessages([
                'captcha'  =>  __('Captcha does not match the image'),
            ]),
        ]);
    }