How to add the CAPTCHA to a customization form in Magento 2 - Magento Source24

 

How to add the CAPTCHA to a customization form in Magento 2 - Magento Source24
How to add the CAPTCHA to a customization form in Magento 2 - Magento Source24

How to add the CAPTCHA to a customization form in Magento 2 - Magento Source24 


Hi magento2 friends welcome back to my Magento 2 Blog series. todays i'm share with you to How to change the font and remove the background image of Captcha in Magento 2.

in magento 2 We will add the CAPTCHA to the Orders and Returns form,

this is the Orders and Returns page, it is a default page is added by Magento 2 core.in magento 2 By default, Magento 2 doesn't allow us to show the CAPTCHA on this form.

So what will we do in this practice?


👉 We will define the new form called "Orders and Returns Form" to the Forms list for applying from the backend.

👉 We will override the template named "guest.form", it is used in the layout named sales_guest_form for adding the CAPTCHA.

👉 We will use observer for validating CAPTCHA on this form.


➤ Let's start practice, we will continue to use the module named PHPCuong_Captcha of the previous lesson. You need to follow steps by step:


First you Download this extension - https://github.com/php-cuong/magento2-captcha


or download from here : https://drive.google.com/file/d/1I-ytxQMP0jcAjUOXkEBOGUY82IX_cohr/view?usp=share_link


Step 1: Declaring a new form called "Orders and Returns Form" to the Forms list : 

➤  Add the following codes to the config.xml available file.

Step 2: Add the CAPTCHA to the Orders and Returns Form

➤  Create the new file named sales_guest_form.xml in the path app\code\PHPCuong\Captcha\view\frontend\layout

➤  Create the new template file named form.phtml in the path app\code\PHPCuong\Captcha\view\frontend\templates\sales\guest

Step 3: Validate CAPTCHA on the Orders and Returns Form

➤  When this form is submitted, the post data will be sent to the URL sales/guest/view, so we need to use the controller predispatch event for validating CAPTCHA on this form. 

➤ That is the action is called when submitting the Orders and Returns Form.

➤ Create the new file named events.xml in the path app\code\PHPCuong\Captcha\etc\frontend

➤  Create the new file named SalesGuestViewObserver.php in the path app\code\PHPCuong\Captcha\Observer

Step 4: Test and See the results : 


Run the command line following :

php bin/magento cache:clean


➤  Go to the backend and navigate to Stores - Settings - Configurations - Customers - Customer Configuration -  CAPTCHA.

➤  Choose the Orders and Returns Form in the list for applying.

➤  Go to the fronted and try to access the Orders and Returns page.


Yeah, it works perfectly.



Deepak Kumar Bind

Success is peace of mind, which is a direct result of self-satisfaction in knowing you made the effort to become the best of which you are capable.

Post a Comment

If you liked this post please do not forget to leave a comment. Thanks

Previous Post Next Post