Article posted Tue Mar 21 2023 Updated Wed Mar 22 2023

Scripts: Adding reCAPTCHA to Sparsh Product Inquiry

Patching allows you to apply updates or fixes without having to modify the original source code. With libraries such as composer you can also automate patch application on deployment. This allows you to make changes to third party modules while still using composer for package management, without needing to install any packages locally or as part of the code repository.

You must be using .git for repository management. If you are, the following example creates a patch file based on the last commit

git format-patch -1 {commit-id} --stdout > patch-name.patch

To then apply a patch, run the following command

git apply patch-name.patch

The below .patch file will update Sparsh ProductInquiry on Magento 2.4.0, to include reCaptcha. An option is added to the Admin panel to include toggling the reCaptcha for the extensions own form.

The below is a good example of a .patch file, however please note that this script is dependent on your own environment, Magento 2 version, and version of 'ProductInquiry' (1.20.0) and where it is installed. Please test before running on a production environment!
diff --git a/app/code/Sparsh/ProductInquiry/Observer/RecapchaFormObserver.php b/app/code/Sparsh/ProductInquiry/Observer/RecapchaFormObserver.php
new file mode 100644
index 00000000..863b68a1
--- /dev/null
+++ b/app/code/Sparsh/ProductInquiry/Observer/RecapchaFormObserver.php
@@ -0,0 +1,48 @@
+<?php
+/**
+ *  Blackmage.co.uk
+ */
+
+namespace Sparsh\ProductInquiry\Observer;
+
+use Magento\Framework\App\Action\Action;
+use Magento\Framework\Event\Observer;
+use Magento\Framework\Event\ObserverInterface;
+use Magento\Framework\Exception\LocalizedException;
+use Magento\Framework\UrlInterface;
+use Magento\ReCaptchaUi\Model\IsCaptchaEnabledInterface;
+use Magento\ReCaptchaUi\Model\RequestHandlerInterface;
+use Magento\Framework\App\Response\RedirectInterface;
+
+class RecapchaFormObserver implements ObserverInterface
+{
+    protected $redirect;
+    private $url;
+    private $isCaptchaEnabled;
+    private $requestHandler;
+
+    public function __construct(
+        UrlInterface $url,
+        IsCaptchaEnabledInterface $isCaptchaEnabled,
+        RequestHandlerInterface $requestHandler,
+        RedirectInterface $redirect
+    ) {
+        $this->url = $url;
+        $this->isCaptchaEnabled = $isCaptchaEnabled;
+        $this->requestHandler = $requestHandler;
+        $this->redirect = $redirect;
+    }
+
+    public function execute(Observer $observer): void
+    {
+        $key = 'product_inquiry';
+        if ($this->isCaptchaEnabled->isCaptchaEnabledFor($key)) {
+            /** @var Action $controller */
+            $controller = $observer->getControllerAction();
+            $request = $controller->getRequest();
+            $response = $controller->getResponse();
+            $redirectOnFailureUrl = $this->redirect->getRedirectUrl();
+            $this->requestHandler->execute($key, $request, $response, $redirectOnFailureUrl);
+        }
+    }
+}
diff --git a/app/code/Sparsh/ProductInquiry/etc/adminhtml/system.xml b/app/code/Sparsh/ProductInquiry/etc/adminhtml/system.xml
index ad812047..61a42e9c 100644
--- a/app/code/Sparsh/ProductInquiry/etc/adminhtml/system.xml
+++ b/app/code/Sparsh/ProductInquiry/etc/adminhtml/system.xml
@@ -1,57 +1,66 @@
-<?xml version="1.0"?>
-<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Config:etc/system_file.xsd">
-    <system>
-        <tab id="sparsh" translate="label" sortOrder="500">
-            <label>Sparsh Extensions</label>
-        </tab>
-        <section id="product_inquiry" translate="label" sortOrder="1" showInDefault="1" showInWebsite="1" showInStore="1">
-            <class>separator-top</class>
-            <label>Product Inquiry</label>
-            <tab>sparsh</tab>
-            <resource>Sparsh_ProductInquiry::product_inquiry</resource>
-            <group id="general" translate="label" type="text" sortOrder="10" showInDefault="1" showInWebsite="1" showInStore="1">
-                <label>General Settings</label>
-                <field id="enable" translate="label" type="select" sortOrder="1" showInDefault="1" showInWebsite="1" showInStore="1">
-                    <label>Enable</label>
-                    <source_model>Magento\Config\Model\Config\Source\Yesno</source_model>
-                </field>
-                <field id="label" translate="label comment" type="text" sortOrder="2" showInDefault="1" showInWebsite="1" showInStore="1">
-                    <label>Label</label>
-                    <comment>Leave label as blank if you just want to hide price without having any inquiry button.</comment>
-                    <depends>
-                        <field id="enable">1</field>
-                    </depends>
-                </field>
-				<field id="is_addtocart_allowed" translate="label" type="select" sortOrder="3" showInDefault="1" showInWebsite="1" showInStore="1">
-                    <label>Allow Add To Cart</label>
-                    <source_model>Magento\Config\Model\Config\Source\Yesno</source_model>
-                    <depends>
-                        <field id="enable">1</field>
-                    </depends>
-                </field>
-				<field id="is_product_price_disclosed" translate="label" type="select" sortOrder="4" showInDefault="1" showInWebsite="1" showInStore="1">
-                    <label>Disclose Product Price</label>
-                    <source_model>Magento\Config\Model\Config\Source\Yesno</source_model>
-                    <depends>
-                        <field id="enable">1</field>
-                    </depends>
-                </field>
-				<field id="sender" translate="label" type="select" sortOrder="5" showInDefault="1" showInWebsite="1" showInStore="1">
-                    <label>To Email</label>
-                    <source_model>Magento\Config\Model\Config\Source\Email\Identity</source_model>
-                    <depends>
-                        <field id="enable">1</field>
-                    </depends>
-                </field>
-                <field id="email_template" translate="label comment" type="select" sortOrder="6" showInDefault="1" showInWebsite="1" showInStore="1" canRestore="1">
-                    <label>Email Template</label>
-                    <comment>Email template chosen based on theme fallback when "Default" option is selected.</comment>
-                    <source_model>Magento\Config\Model\Config\Source\Email\Template</source_model>
-                    <depends>
-                        <field id="enable">1</field>
-                    </depends>
-                </field>
-            </group>
-        </section>
-    </system>
-</config>
\ No newline at end of file
+<?xml version="1.0"?>
+<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Config:etc/system_file.xsd">
+    <system>
+        <tab id="sparsh" translate="label" sortOrder="500">
+            <label>Sparsh Extensions</label>
+        </tab>
+        <section id="recaptcha_frontend">
+            <group id="type_for">
+                <field id="product_inquiry" translate="label" type="select" sortOrder="140" showInDefault="1"
+                       showInWebsite="1" showInStore="0" canRestore="1">
+                    <label>Enable for Sparsh Product Inquiry (Blackmage.co.uk fix)</label>
+                    <source_model>Magento\ReCaptchaAdminUi\Model\OptionSource\Type</source_model>
+                </field>
+            </group>
+        </section>
+        <section id="product_inquiry" translate="label" sortOrder="1" showInDefault="1" showInWebsite="1" showInStore="1">
+            <class>separator-top</class>
+            <label>Product Inquiry</label>
+            <tab>sparsh</tab>
+            <resource>Sparsh_ProductInquiry::product_inquiry</resource>
+            <group id="general" translate="label" type="text" sortOrder="10" showInDefault="1" showInWebsite="1" showInStore="1">
+                <label>General Settings</label>
+                <field id="enable" translate="label" type="select" sortOrder="1" showInDefault="1" showInWebsite="1" showInStore="1">
+                    <label>Enable</label>
+                    <source_model>Magento\Config\Model\Config\Source\Yesno</source_model>
+                </field>
+                <field id="label" translate="label comment" type="text" sortOrder="2" showInDefault="1" showInWebsite="1" showInStore="1">
+                    <label>Label</label>
+                    <comment>Leave label as blank if you just want to hide price without having any inquiry button.</comment>
+                    <depends>
+                        <field id="enable">1</field>
+                    </depends>
+                </field>
+				<field id="is_addtocart_allowed" translate="label" type="select" sortOrder="3" showInDefault="1" showInWebsite="1" showInStore="1">
+                    <label>Allow Add To Cart</label>
+                    <source_model>Magento\Config\Model\Config\Source\Yesno</source_model>
+                    <depends>
+                        <field id="enable">1</field>
+                    </depends>
+                </field>
+				<field id="is_product_price_disclosed" translate="label" type="select" sortOrder="4" showInDefault="1" showInWebsite="1" showInStore="1">
+                    <label>Disclose Product Price</label>
+                    <source_model>Magento\Config\Model\Config\Source\Yesno</source_model>
+                    <depends>
+                        <field id="enable">1</field>
+                    </depends>
+                </field>
+				<field id="sender" translate="label" type="select" sortOrder="5" showInDefault="1" showInWebsite="1" showInStore="1">
+                    <label>To Email</label>
+                    <source_model>Magento\Config\Model\Config\Source\Email\Identity</source_model>
+                    <depends>
+                        <field id="enable">1</field>
+                    </depends>
+                </field>
+                <field id="email_template" translate="label comment" type="select" sortOrder="6" showInDefault="1" showInWebsite="1" showInStore="1" canRestore="1">
+                    <label>Email Template</label>
+                    <comment>Email template chosen based on theme fallback when "Default" option is selected.</comment>
+                    <source_model>Magento\Config\Model\Config\Source\Email\Template</source_model>
+                    <depends>
+                        <field id="enable">1</field>
+                    </depends>
+                </field>
+            </group>
+        </section>
+    </system>
+</config>
diff --git a/app/code/Sparsh/ProductInquiry/etc/config.xml b/app/code/Sparsh/ProductInquiry/etc/config.xml
index fadaa078..c31cd8e8 100644
--- a/app/code/Sparsh/ProductInquiry/etc/config.xml
+++ b/app/code/Sparsh/ProductInquiry/etc/config.xml
@@ -1,15 +1,20 @@
-<?xml version="1.0"?>
-<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Store:etc/config.xsd">
-    <default>
-        <product_inquiry>
-            <general>
-                <enable>0</enable>
-                <label>Inquiry</label>
-                <is_addtocart_allowed>1</is_addtocart_allowed>
-                <is_product_price_disclosed>1</is_product_price_disclosed>
-                <sender>general</sender>
-                <email_template>product_inquiry_general_email_template</email_template>
-            </general>
-        </product_inquiry>
-    </default>
-</config>
\ No newline at end of file
+<?xml version="1.0"?>
+<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Store:etc/config.xsd">
+    <default>
+        <recaptcha_frontend>
+            <type_for>
+                <product_inquiry/>
+            </type_for>
+        </recaptcha_frontend>
+        <product_inquiry>
+            <general>
+                <enable>0</enable>
+                <label>Inquiry</label>
+                <is_addtocart_allowed>1</is_addtocart_allowed>
+                <is_product_price_disclosed>1</is_product_price_disclosed>
+                <sender>general</sender>
+                <email_template>product_inquiry_general_email_template</email_template>
+            </general>
+        </product_inquiry>
+    </default>
+</config>
diff --git a/app/code/Sparsh/ProductInquiry/etc/frontend/events.xml b/app/code/Sparsh/ProductInquiry/etc/frontend/events.xml
new file mode 100644
index 00000000..6a3ddbea
--- /dev/null
+++ b/app/code/Sparsh/ProductInquiry/etc/frontend/events.xml
@@ -0,0 +1,7 @@
+<?xml version="1.0"?>
+<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+        xsi:noNamespaceSchemaLocation="urn:magento:framework:Event/etc/events.xsd">
+    <event name="controller_action_predispatch_product_inquiry_index_submitted">
+        <observer name="recaptcha_product_inquiry_form" instance="Sparsh\ProductInquiry\Observer\RecapchaFormObserver"/>
+    </event>
+</config>
diff --git a/app/code/Sparsh/ProductInquiry/view/frontend/layout/catalog_category_view.xml b/app/code/Sparsh/ProductInquiry/view/frontend/layout/catalog_category_view.xml
index 760b6efd..577788bf 100644
--- a/app/code/Sparsh/ProductInquiry/view/frontend/layout/catalog_category_view.xml
+++ b/app/code/Sparsh/ProductInquiry/view/frontend/layout/catalog_category_view.xml
@@ -1,11 +1,30 @@
-<?xml version="1.0"?>
-<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance dc" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
-    <referenceContainer name="content">
-        <block class="Magento\Framework\View\Element\Template" name="sparsh_product_inquiry" template="Sparsh_ProductInquiry::catalog/product/view/form.phtml" />
-    </referenceContainer>
-    <referenceBlock name="category.products.list">
-        <action method="setTemplate">
-            <argument name="template" xsi:type="string">Sparsh_ProductInquiry::catalog/product/list.phtml</argument>
-        </action>
-    </referenceBlock>
-</page>
\ No newline at end of file
+<?xml version="1.0"?>
+<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance dc" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
+    <referenceContainer name="content">
+        <block class="Magento\Framework\View\Element\Template" name="sparsh_product_inquiry" template="Sparsh_ProductInquiry::catalog/product/view/form.phtml">
+            <container name="form.additional.info.product_inquiry.recaptcha">
+                <block class="Magento\ReCaptchaUi\Block\ReCaptcha"
+                       name="recaptcha"
+                       after="-"
+                       template="Magento_ReCaptchaFrontendUi::recaptcha.phtml"
+                       ifconfig="recaptcha_frontend/type_for/product_inquiry">
+                    <arguments>
+                        <argument name="recaptcha_for" xsi:type="string">product_inquiry</argument>
+                        <argument name="jsLayout" xsi:type="array">
+                            <item name="components" xsi:type="array">
+                                <item name="recaptcha" xsi:type="array">
+                                    <item name="component" xsi:type="string">Magento_ReCaptchaFrontendUi/js/reCaptcha</item>
+                                </item>
+                            </item>
+                        </argument>
+                    </arguments>
+                </block>
+            </container>
+        </block>
+    </referenceContainer>
+    <referenceBlock name="category.products.list">
+        <action method="setTemplate">
+            <argument name="template" xsi:type="string">Sparsh_ProductInquiry::catalog/product/list.phtml</argument>
+        </action>
+    </referenceBlock>
+</page>
diff --git a/app/code/Sparsh/ProductInquiry/view/frontend/layout/catalog_product_compare_index.xml b/app/code/Sparsh/ProductInquiry/view/frontend/layout/catalog_product_compare_index.xml
index b60f3a62..ee4d8425 100644
--- a/app/code/Sparsh/ProductInquiry/view/frontend/layout/catalog_product_compare_index.xml
+++ b/app/code/Sparsh/ProductInquiry/view/frontend/layout/catalog_product_compare_index.xml
@@ -1,11 +1,30 @@
-<?xml version="1.0"?>
-<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance dc" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
-    <referenceContainer name="content">
-        <block class="Magento\Framework\View\Element\Template" name="sparsh_product_inquiry" template="Sparsh_ProductInquiry::catalog/product/view/form.phtml" />
-    </referenceContainer>
-    <referenceBlock name="catalog.compare.list">
-       <action method="setTemplate">
-           <argument name="template" xsi:type="string">Sparsh_ProductInquiry::catalog/product/compare/list.phtml</argument>
-       </action>
-   </referenceBlock>
-</page>
+<?xml version="1.0"?>
+<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance dc" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
+    <referenceContainer name="content">
+        <block class="Magento\Framework\View\Element\Template" name="sparsh_product_inquiry" template="Sparsh_ProductInquiry::catalog/product/view/form.phtml">
+            <container name="form.additional.info.product_inquiry.recaptcha">
+                <block class="Magento\ReCaptchaUi\Block\ReCaptcha"
+                       name="recaptcha"
+                       after="-"
+                       template="Magento_ReCaptchaFrontendUi::recaptcha.phtml"
+                       ifconfig="recaptcha_frontend/type_for/product_inquiry">
+                    <arguments>
+                        <argument name="recaptcha_for" xsi:type="string">product_inquiry</argument>
+                        <argument name="jsLayout" xsi:type="array">
+                            <item name="components" xsi:type="array">
+                                <item name="recaptcha" xsi:type="array">
+                                    <item name="component" xsi:type="string">Magento_ReCaptchaFrontendUi/js/reCaptcha</item>
+                                </item>
+                            </item>
+                        </argument>
+                    </arguments>
+                </block>
+            </container>
+        </block>
+    </referenceContainer>
+    <referenceBlock name="catalog.compare.list">
+       <action method="setTemplate">
+           <argument name="template" xsi:type="string">Sparsh_ProductInquiry::catalog/product/compare/list.phtml</argument>
+       </action>
+   </referenceBlock>
+</page>
diff --git a/app/code/Sparsh/ProductInquiry/view/frontend/layout/catalog_product_view.xml b/app/code/Sparsh/ProductInquiry/view/frontend/layout/catalog_product_view.xml
index afa149c0..202bc4ec 100644
--- a/app/code/Sparsh/ProductInquiry/view/frontend/layout/catalog_product_view.xml
+++ b/app/code/Sparsh/ProductInquiry/view/frontend/layout/catalog_product_view.xml
@@ -1,16 +1,35 @@
-<?xml version="1.0"?>
-<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance dc" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
-    <referenceContainer name="content">
-        <block class="Magento\Framework\View\Element\Template" name="product.inquiry" template="Sparsh_ProductInquiry::catalog/product/view/form.phtml" before="product.info.extrahint" group="main_group" />
-    </referenceContainer>
-    <referenceBlock name="product.info.addtocart">
-        <action method="setTemplate">
-            <argument name="template" xsi:type="string">Sparsh_ProductInquiry::catalog/product/view/addtocart.phtml</argument>
-        </action>
-    </referenceBlock>
-    <referenceBlock name="product.info.addtocart.additional">
-        <action method="setTemplate">
-            <argument name="template" xsi:type="string">Sparsh_ProductInquiry::catalog/product/view/addtocart.phtml</argument>
-        </action>
-    </referenceBlock>
-</page>
\ No newline at end of file
+<?xml version="1.0"?>
+<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance dc" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
+    <referenceContainer name="content">
+        <block class="Magento\Framework\View\Element\Template" name="product.inquiry" template="Sparsh_ProductInquiry::catalog/product/view/form.phtml" before="product.info.extrahint" group="main_group">
+            <container name="form.additional.info.product_inquiry.recaptcha">
+                <block class="Magento\ReCaptchaUi\Block\ReCaptcha"
+                       name="recaptcha"
+                       after="-"
+                       template="Magento_ReCaptchaFrontendUi::recaptcha.phtml"
+                       ifconfig="recaptcha_frontend/type_for/product_inquiry">
+                    <arguments>
+                        <argument name="recaptcha_for" xsi:type="string">product_inquiry</argument>
+                        <argument name="jsLayout" xsi:type="array">
+                            <item name="components" xsi:type="array">
+                                <item name="recaptcha" xsi:type="array">
+                                    <item name="component" xsi:type="string">Magento_ReCaptchaFrontendUi/js/reCaptcha</item>
+                                </item>
+                            </item>
+                        </argument>
+                    </arguments>
+                </block>
+            </container>
+        </block>
+    </referenceContainer>
+    <referenceBlock name="product.info.addtocart">
+        <action method="setTemplate">
+            <argument name="template" xsi:type="string">Sparsh_ProductInquiry::catalog/product/view/addtocart.phtml</argument>
+        </action>
+    </referenceBlock>
+    <referenceBlock name="product.info.addtocart.additional">
+        <action method="setTemplate">
+            <argument name="template" xsi:type="string">Sparsh_ProductInquiry::catalog/product/view/addtocart.phtml</argument>
+        </action>
+    </referenceBlock>
+</page>
diff --git a/app/code/Sparsh/ProductInquiry/view/frontend/layout/catalogsearch_advanced_result.xml b/app/code/Sparsh/ProductInquiry/view/frontend/layout/catalogsearch_advanced_result.xml
index 243311f3..c08aecf8 100644
--- a/app/code/Sparsh/ProductInquiry/view/frontend/layout/catalogsearch_advanced_result.xml
+++ b/app/code/Sparsh/ProductInquiry/view/frontend/layout/catalogsearch_advanced_result.xml
@@ -1,11 +1,30 @@
 <?xml version="1.0"?>
 <page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance dc" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
     <referenceContainer name="content">
-        <block class="Magento\Framework\View\Element\Template" name="sparsh_product_inquiry" template="Sparsh_ProductInquiry::catalog/product/view/form.phtml" />
+        <block class="Magento\Framework\View\Element\Template" name="sparsh_product_inquiry" template="Sparsh_ProductInquiry::catalog/product/view/form.phtml">
+            <container name="form.additional.info.product_inquiry.recaptcha">
+                <block class="Magento\ReCaptchaUi\Block\ReCaptcha"
+                       name="recaptcha"
+                       after="-"
+                       template="Magento_ReCaptchaFrontendUi::recaptcha.phtml"
+                       ifconfig="recaptcha_frontend/type_for/product_inquiry">
+                    <arguments>
+                        <argument name="recaptcha_for" xsi:type="string">product_inquiry</argument>
+                        <argument name="jsLayout" xsi:type="array">
+                            <item name="components" xsi:type="array">
+                                <item name="recaptcha" xsi:type="array">
+                                    <item name="component" xsi:type="string">Magento_ReCaptchaFrontendUi/js/reCaptcha</item>
+                                </item>
+                            </item>
+                        </argument>
+                    </arguments>
+                </block>
+            </container>
+        </block>
     </referenceContainer>
     <referenceBlock name="search_result_list">
         <action method="setTemplate">
             <argument name="template" xsi:type="string">Sparsh_ProductInquiry::catalog/product/list.phtml</argument>
         </action>
     </referenceBlock>
-</page>
\ No newline at end of file
+</page>
diff --git a/app/code/Sparsh/ProductInquiry/view/frontend/layout/catalogsearch_result_index.xml b/app/code/Sparsh/ProductInquiry/view/frontend/layout/catalogsearch_result_index.xml
index ee27f22e..c08aecf8 100644
--- a/app/code/Sparsh/ProductInquiry/view/frontend/layout/catalogsearch_result_index.xml
+++ b/app/code/Sparsh/ProductInquiry/view/frontend/layout/catalogsearch_result_index.xml
@@ -1,11 +1,30 @@
-<?xml version="1.0"?>
-<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance dc" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
-    <referenceContainer name="content">
-        <block class="Magento\Framework\View\Element\Template" name="sparsh_product_inquiry" template="Sparsh_ProductInquiry::catalog/product/view/form.phtml" />
-    </referenceContainer>
-    <referenceBlock name="search_result_list">
-        <action method="setTemplate">
-            <argument name="template" xsi:type="string">Sparsh_ProductInquiry::catalog/product/list.phtml</argument>
-        </action>
-    </referenceBlock>
-</page>
\ No newline at end of file
+<?xml version="1.0"?>
+<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance dc" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
+    <referenceContainer name="content">
+        <block class="Magento\Framework\View\Element\Template" name="sparsh_product_inquiry" template="Sparsh_ProductInquiry::catalog/product/view/form.phtml">
+            <container name="form.additional.info.product_inquiry.recaptcha">
+                <block class="Magento\ReCaptchaUi\Block\ReCaptcha"
+                       name="recaptcha"
+                       after="-"
+                       template="Magento_ReCaptchaFrontendUi::recaptcha.phtml"
+                       ifconfig="recaptcha_frontend/type_for/product_inquiry">
+                    <arguments>
+                        <argument name="recaptcha_for" xsi:type="string">product_inquiry</argument>
+                        <argument name="jsLayout" xsi:type="array">
+                            <item name="components" xsi:type="array">
+                                <item name="recaptcha" xsi:type="array">
+                                    <item name="component" xsi:type="string">Magento_ReCaptchaFrontendUi/js/reCaptcha</item>
+                                </item>
+                            </item>
+                        </argument>
+                    </arguments>
+                </block>
+            </container>
+        </block>
+    </referenceContainer>
+    <referenceBlock name="search_result_list">
+        <action method="setTemplate">
+            <argument name="template" xsi:type="string">Sparsh_ProductInquiry::catalog/product/list.phtml</argument>
+        </action>
+    </referenceBlock>
+</page>
diff --git a/app/code/Sparsh/ProductInquiry/view/frontend/layout/wishlist_index_index.xml b/app/code/Sparsh/ProductInquiry/view/frontend/layout/wishlist_index_index.xml
index 27b76f5e..04717fe1 100644
--- a/app/code/Sparsh/ProductInquiry/view/frontend/layout/wishlist_index_index.xml
+++ b/app/code/Sparsh/ProductInquiry/view/frontend/layout/wishlist_index_index.xml
@@ -1,14 +1,34 @@
-<?xml version="1.0"?>
-<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance dc" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
-<head>
+<?xml version="1.0"?>
+<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance dc" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
+<head>
      <css src="Sparsh_ProductInquiry::css/modelpopup.css"/>
 </head>
     <referenceContainer name="content">
-        <block class="Magento\Framework\View\Element\Template" name="sparsh_product_inquiry" template="Sparsh_ProductInquiry::catalog/product/view/form.phtml" />
+        <block class="Magento\Framework\View\Element\Template" name="sparsh_product_inquiry" template="Sparsh_ProductInquiry::catalog/product/view/form.phtml"
+        >
+            <container name="form.additional.info.product_inquiry.recaptcha">
+                <block class="Magento\ReCaptchaUi\Block\ReCaptcha"
+                       name="recaptcha"
+                       after="-"
+                       template="Magento_ReCaptchaFrontendUi::recaptcha.phtml"
+                       ifconfig="recaptcha_frontend/type_for/product_inquiry">
+                    <arguments>
+                        <argument name="recaptcha_for" xsi:type="string">product_inquiry</argument>
+                        <argument name="jsLayout" xsi:type="array">
+                            <item name="components" xsi:type="array">
+                                <item name="recaptcha" xsi:type="array">
+                                    <item name="component" xsi:type="string">Magento_ReCaptchaFrontendUi/js/reCaptcha</item>
+                                </item>
+                            </item>
+                        </argument>
+                    </arguments>
+                </block>
+            </container>
+        </block>
     </referenceContainer>
     <referenceBlock name="customer.wishlist.item.cart">
        <action method="setTemplate">
            <argument name="template" xsi:type="string">Sparsh_ProductInquiry::item/column/cart.phtml</argument>
        </action>
    </referenceBlock>
-</page>
\ No newline at end of file
+</page>
diff --git a/app/code/Sparsh/ProductInquiry/view/frontend/templates/catalog/product/view/form.phtml b/app/code/Sparsh/ProductInquiry/view/frontend/templates/catalog/product/view/form.phtml
index 0b015626..7fc2c075 100644
--- a/app/code/Sparsh/ProductInquiry/view/frontend/templates/catalog/product/view/form.phtml
+++ b/app/code/Sparsh/ProductInquiry/view/frontend/templates/catalog/product/view/form.phtml
@@ -142,6 +142,7 @@ $customerEmail = $productInquiryHelper->getUserEmail();
                 <input placeholder="<?= $block->escapeHtmlAttr(__('SKU')) ?>" name="sparsh_product_inquiry_sku" title="<?= $block->escapeHtmlAttr(__('SKU')) ?>" value="<?= $block->escapeHtmlAttr($this->helper(\Magento\Contact\Helper\Data::class)->getPostValue('sparsh_product_inquiry_sku')) ?>" class="input-text sparsh_product_inquiry_sku" type="hidden" data-validate='{"required":true}' />
             </div>
         </fieldset>
+        <?= $block->getChildHtml('form.additional.info.product_inquiry.recaptcha') ?>
         <div class="actions-toolbar">
             <div class="primary">
                 <button type="submit" title="<?= $block->escapeHtmlAttr(__('Submit')) ?>" class="action submit primary" id="sparsh_product_inquiry_submit">