I'm developing a custom module which contains a form submission. I would like to add a captcha to it. And we want to use the Magento default captcha library so that the captcha is consistent with the one in registration form.
Magento2 Captcha – How to Add Captcha to a Custom Form
captchamagento2
Best Answer
You need follow some step for using magento captcha into custom module.
Step 1:
Create
Vendor/Module/etc/config.xml
Step 2:
Goto Admin -> Stores -> Configuration -> Customer -> Customer Configuration -> Captcha and configure. You can able to see new forms value Custom Form
Step 3:
Create
Vendor/Module/view/frontend/layout/yourroutid_index_index.xml
Step 4:
Create
Vendor/Module/Block/CaptchaForm.php
Step 5:
Create
Vendor/Moduel/view/frontend/templates/captchaform.phtml
Now you can able to see captcha into your form. Now need to validation your captcha using observer. So I use post controller predispatch event for validation.
Step 6:
Create
Vendor/Module/etc/frontend/events.xml
Step 7:
Create
Vendor/Module/Observer/CheckCustomFormObserver.php