karser / KarserRecaptcha3Bundle

Google ReCAPTCHA v3 for Symfony
MIT License
160 stars 22 forks source link

The captcha value is missing #48

Closed BarsikCat closed 2 years ago

BarsikCat commented 2 years ago

Hello,

I'm continually getting "The captcha value is missing" message.

This is my first PHP project for more than a decade :)

The browser says that the form is successfully posted:

Form data:

contact_us[captcha]: 
03AGdBq26czW2_CFHbLvnvfy-qrzIYWMr1drr1WhcEyjJrElxSTHpG1MepvjeZF8Yafd2guBXZ9bbAMbSjdOJnli0RleE2f7rtht9-iRtKwxFqzn4tGn7ReDYesItAv8OvgbR7lF3Zw6o8IJG0QZlSL_aZrywQVfXUZ9TCsBYG0gDeW-X-ymG97XqgXbHX43bTe6oOmel5wNk94W2FTtiXgVxR0TLdG5QRnMVXPL06Cu6Y-TMEd5KH0hrADiSnZG7EZaTQSJNiVcDEB9WSX-rcnacgiHzkIgLVs9f6NrDpmS2lBpl1Lv6OCaYg0Jz1EFJx_fr2s_fP2vltuOWHOHojyWjdC30rJySUZ_35Yvslh4A8TmiNfGDn7bRlO2c990GVB9f5VINTa9yn1Zb6dAcZxDlFXrWg83Q5gV9wSL5y6ACALvrdi1IwvyqhDiK2TDydwxm741VMvttN
contact_us[_token]:
9af332ff29b1fead7c8a058.VhAT8CLqFjeAw7lsC2tQ_gKLAhNUODTRuizgDsU_HuA.LCMipHK4Z3i5p_obbj0XjDfUXVwGdXi76xuCfqZUf9MsPWCBRb9mR62FjQ

But debug details look strange for me: debug

I can share the entire project :)

karser commented 2 years ago

Hello, that's weird. Can you show how you create Recaptcha3Type, please?

karser commented 2 years ago

Also, try going through the troubleshooting checklist. I'm sure there is some misconfiguration issue

BarsikCat commented 2 years ago

Thanks for the reply!

I can easily misconfigure something because I am back to PHP after a long period of time. It looks pretty different for me :)

class ContactUsType extends AbstractType
{
    public function buildForm(FormBuilderInterface $builder, array $options): void
    {
        $builder
            ->add('name', TextType::class, [
                'label' => "Your name:",
                'required' => false
            ])
            ->add('email', EmailType::class, [
                'label' => "Your email address:",
                'help' => "We'll never share your email with anyone else.",
                'required' => false
            ])
            ->add('message', TextareaType::class, [
                'label' => "Your message:",
                'attr' => ['rows' => '7'],
            ])
            ->add('send', SubmitType::class, [
                'label' => "Send Message",
            ])
            ->add('captcha', Recaptcha3Type::class, [
                'constraints' => new Recaptcha3(),
                'action_name' => 'contacts',
                //'script_nonce_csp' => $nonceCSP,
            ])
        ;
    }

    public function configureOptions(OptionsResolver $resolver): void
    {
        $resolver->setDefaults([
            'data_class' => ContactUs::class,
        ]);
    }
}
namespace App\Entity;

class ContactUs
{
    public string $captcha;

    protected string $name;
    protected string $email;
    protected string $message;

    public function getName(): string
    {
        return $this->name;
    }

    public function setName(string $name): void
    {
        $this->name = $name;
    }

    public function getEmail(): string
    {
        return $this->email;
    }

    public function setEmail(string $email): void
    {
        $this->email = $email;
    }

    public function getMessage(): string
    {
        return $this->message;
    }

    public function setMessage(string $message): void
    {
        $this->message = $message;
    }

}

In your "the troubleshooting checklist" the Captcha setup picture is truncated. I have 3 checkboxes bellow. They are translated to my language but mean the following: Check reCAPTCHA solution source - Yes, Allow AMP-page - No, Report to owner - Yes

More pictures for you: truble

truble2

truble3

It is uploaded to a test domain and I can share GitHub repository with you.

karser commented 2 years ago

All looks good. Please, share the repo

BarsikCat commented 2 years ago

Invite sent. Complete newbie (in modern PHP) form processing realization made from current Symfony documentation.

karser commented 2 years ago

thank you, I'll take a look tomorrow

On Fri, Oct 15, 2021, 1:15 AM BarsikCat @.***> wrote:

Invite sent. Complete newbie (in modern PHP) form processing realization made from current Symfony documentation.

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/karser/KarserRecaptcha3Bundle/issues/48#issuecomment-943778973, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAMY6GOCNXI3DMRFQGZPFFLUG5JBJANCNFSM5F5PONUA . Triage notifications on the go with GitHub Mobile for iOS https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675 or Android https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub.

karser commented 2 years ago

Figured it out. You don't need $captcha property on ContactUs entity because Recaptcha3Type is not mapped That's what you need to do to make it work: Screenshot from 2021-10-15 13-16-18 Screenshot from 2021-10-15 13-16-22

BarsikCat commented 2 years ago

Many thanks!