{"id":2264,"date":"2025-01-10T13:47:51","date_gmt":"2025-01-10T11:47:51","guid":{"rendered":"https:\/\/plumrocket.com\/learn\/?p=2264"},"modified":"2026-08-19T12:17:50","modified_gmt":"2026-08-19T09:17:50","slug":"how-to-add-google-recaptcha-to-custom-form-in-magento-2","status":"publish","type":"post","link":"https:\/\/plumrocket.com\/learn\/magento-2-add-google-recaptcha","title":{"rendered":"How to Add Google reCAPTCHA to Custom Form\u200b in Magento 2"},"content":{"rendered":"\n<figure class=\"wp-block-image size-full disable_zoom\"><img loading=\"lazy\" decoding=\"async\" width=\"1600\" height=\"600\" src=\"https:\/\/plumrocket.com\/learn\/wp-content\/uploads\/2025\/01\/add-google-recaptcha-to-custom-form-1.png\" alt=\"How to Add Google reCAPTCHA to Custom Form\u200b in Magento 2\" class=\"wp-image-2277\" srcset=\"https:\/\/plumrocket.com\/learn\/wp-content\/uploads\/2025\/01\/add-google-recaptcha-to-custom-form-1.png 1600w, https:\/\/plumrocket.com\/learn\/wp-content\/uploads\/2025\/01\/add-google-recaptcha-to-custom-form-1-300x113.png 300w, https:\/\/plumrocket.com\/learn\/wp-content\/uploads\/2025\/01\/add-google-recaptcha-to-custom-form-1-1024x384.png 1024w, https:\/\/plumrocket.com\/learn\/wp-content\/uploads\/2025\/01\/add-google-recaptcha-to-custom-form-1-768x288.png 768w, https:\/\/plumrocket.com\/learn\/wp-content\/uploads\/2025\/01\/add-google-recaptcha-to-custom-form-1-1536x576.png 1536w, https:\/\/plumrocket.com\/learn\/wp-content\/uploads\/2025\/01\/add-google-recaptcha-to-custom-form-1-1568x588.png 1568w\" sizes=\"auto, (max-width: 1600px) 100vw, 1600px\" \/><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">Google reCAPTCHA helps protect websites from spam, bot attacks, and other automated form submissions.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Adding reCAPTCHA to your Magento 2 custom forms adds an essential layer of security, ensuring only genuine user interactions are processed by your site.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Magento 2 already includes a built-in implementation of Google reCAPTCHA for standard frontend forms, such as:<\/p>\n\n\n\n<ol class=\"wp-block-list\">\n<li>Customer Login<\/li>\n\n\n\n<li>Forgot Password<\/li>\n\n\n\n<li>Create New Customer Account<\/li>\n\n\n\n<li>Edit Customer Account<\/li>\n\n\n\n<li>Contact Us<\/li>\n\n\n\n<li>Product Review<\/li>\n\n\n\n<li>Newsletter Subscription<\/li>\n\n\n\n<li>Send to Friend<\/li>\n\n\n\n<li>Checkout\/Placing Order<\/li>\n\n\n\n<li>Coupon Codes, and\u00a0<\/li>\n\n\n\n<li>PayPal PayflowPro payment.<\/li>\n<\/ol>\n\n\n\n<p class=\"wp-block-paragraph\">Additionally, Magento\u2019s flexibility allows us to add Google reCAPTCHA to custom forms as needed. This guide will walk you through the process of configuring Google reCAPTCHA in Magento 2, creating a custom extension for your form, and integrating reCAPTCHA into the form template.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>How to Add Google reCAPTCHA to Custom Form in Magento 2<\/strong><\/p>\n\n\n\n<ol class=\"wp-block-list\">\n<li><a href=\"#Step 1\">Configure Google reCAPTCHA in Magento 2<\/a><\/li>\n\n\n\n<li><a href=\"#Step 2\">Create a Custom Extension to Display Your Custom Form<\/a><\/li>\n\n\n\n<li><a href=\"#Step 3\">Add the Magento 2 Custom Form to the List of Frontend reCAPTCHA<\/a><\/li>\n\n\n\n<li><a href=\"#Step 4\">Integrate Google reCAPTCHA into the Custom Form Template<\/a><\/li>\n\n\n\n<li><a href=\"#Step 5\">Build a Controller to Handle Custom Form Submissions<\/a><\/li>\n\n\n\n<li><a href=\"#Step 6\">Validate Google reCAPTCHA for the Custom Form in Magento 2<\/a><\/li>\n<\/ol>\n\n\n\n<div class=\"wp-block-cover is-light\" style=\"min-height:200px;aspect-ratio:unset;\"><img loading=\"lazy\" decoding=\"async\" width=\"800\" height=\"234\" class=\"wp-block-cover__image-background wp-image-2296\" alt=\"\" src=\"https:\/\/plumrocket.com\/learn\/wp-content\/uploads\/2025\/01\/add-google-recaptcha-to-custom-form-1-2.png\" style=\"object-position:92% 39%\" data-object-fit=\"cover\" data-object-position=\"92% 39%\" srcset=\"https:\/\/plumrocket.com\/learn\/wp-content\/uploads\/2025\/01\/add-google-recaptcha-to-custom-form-1-2.png 800w, https:\/\/plumrocket.com\/learn\/wp-content\/uploads\/2025\/01\/add-google-recaptcha-to-custom-form-1-2-300x88.png 300w, https:\/\/plumrocket.com\/learn\/wp-content\/uploads\/2025\/01\/add-google-recaptcha-to-custom-form-1-2-768x225.png 768w\" sizes=\"auto, (max-width: 800px) 100vw, 800px\" \/><span aria-hidden=\"true\" class=\"wp-block-cover__background has-background-dim-0 has-background-dim\"><\/span><div class=\"wp-block-cover__inner-container is-layout-flow wp-block-cover-is-layout-flow\">\n<p class=\"has-text-align-center has-dark-gray-color has-text-color wp-block-paragraph\" style=\"font-size:24px\"><span class=\"has-inline-color has-dark-gray-color\"><strong>Struggling<\/strong><\/span> <span class=\"has-inline-color has-dark-gray-color\"><strong>to Add Google reCAPTCHA to Custom Forms?<\/strong><\/span><\/p>\n\n\n\n<p class=\"has-text-align-center has-dark-gray-color has-text-color wp-block-paragraph\">Our expert developers can help you seamlessly integrate reCAPTCHA and enhance your form security while minimizing user friction.<\/p>\n\n\n\n<div class=\"wp-block-buttons is-horizontal is-content-justification-center is-layout-flex wp-container-core-buttons-is-layout-7d812b4c wp-block-buttons-is-layout-flex\">\n<div class=\"wp-block-button\"><a class=\"wp-block-button__link has-white-color has-text-color has-background wp-element-button\" href=\"\/magento-development\" style=\"background-color:#e6621b\" target=\"_blank\" rel=\"magento-development noopener\">Get Help Now<\/a><\/div>\n<\/div>\n<\/div><\/div>\n\n\n\n<h2 id=\"Step 1\" class=\"wp-block-heading\">Step 1. \u0421onfigure Google reCAPTCHA on Magento 2<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">First, register your site at <a href=\"https:\/\/www.google.com\/recaptcha\/admin\/create\" target=\"_blank\" rel=\"noreferrer noopener\">Google reCAPTCHA<\/a>, and select the type of reCAPTCHA you want to use.<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"1206\" height=\"545\" src=\"https:\/\/plumrocket.com\/learn\/wp-content\/uploads\/2025\/01\/add-google-recaptcha-to-custom-form-1-1.png\" alt=\"Step 1: register your website at Google reCAPTCHA\" class=\"wp-image-2280\" srcset=\"https:\/\/plumrocket.com\/learn\/wp-content\/uploads\/2025\/01\/add-google-recaptcha-to-custom-form-1-1.png 1206w, https:\/\/plumrocket.com\/learn\/wp-content\/uploads\/2025\/01\/add-google-recaptcha-to-custom-form-1-1-300x136.png 300w, https:\/\/plumrocket.com\/learn\/wp-content\/uploads\/2025\/01\/add-google-recaptcha-to-custom-form-1-1-1024x463.png 1024w, https:\/\/plumrocket.com\/learn\/wp-content\/uploads\/2025\/01\/add-google-recaptcha-to-custom-form-1-1-768x347.png 768w\" sizes=\"auto, (max-width: 1206px) 100vw, 1206px\" \/><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">Then, go to<strong> Stores &gt; Configuration &gt; Security &gt; Google reCAPTCHA Storefront &gt; reCAPTCHA<\/strong> <strong>v2 (&#8220;I am not a robot&#8221;) \/ reCAPTCHA v2 Invisible \/ reCAPTCHA v3 Invisible<\/strong> and enter the site key and secret key you created on Google reCAPTCHA after registering. Make sure that the setting name in Magento matches the type of Google reCAPTCHA you created (e.g., reCAPTCHA v2 or v3).<\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"1190\" height=\"567\" src=\"https:\/\/plumrocket.com\/learn\/wp-content\/uploads\/2025\/01\/add-google-recaptcha-to-custom-form-2.png\" alt=\"Step 1: enter the site key and secret key\" class=\"wp-image-2281\" srcset=\"https:\/\/plumrocket.com\/learn\/wp-content\/uploads\/2025\/01\/add-google-recaptcha-to-custom-form-2.png 1190w, https:\/\/plumrocket.com\/learn\/wp-content\/uploads\/2025\/01\/add-google-recaptcha-to-custom-form-2-300x143.png 300w, https:\/\/plumrocket.com\/learn\/wp-content\/uploads\/2025\/01\/add-google-recaptcha-to-custom-form-2-1024x488.png 1024w, https:\/\/plumrocket.com\/learn\/wp-content\/uploads\/2025\/01\/add-google-recaptcha-to-custom-form-2-768x366.png 768w\" sizes=\"auto, (max-width: 1190px) 100vw, 1190px\" \/><\/figure>\n<\/div>\n\n\n<h2 id=\"Step 2\" class=\"wp-block-heading\">Step 2. Create a Custom Extension to Display Your Custom Form<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">We need to create the following files.<\/p>\n\n\n\n<div class=\"wp-block-prismatic-blocks\"><div class=\"prism-title\">app\/code\/Vendor\/CustomFormRecaptcha\/registration.php<\/div><pre><code class=\"language-php\" data-line=\"\">&lt;?php\nuse Magento\\Framework\\Component\\ComponentRegistrar;\nComponentRegistrar::register(\n   ComponentRegistrar::MODULE, &#039;Vendor_CustomFormRecaptcha&#039;,\n   __DIR__\n);\n<\/code><\/pre><\/div>\n\n\n\n<div class=\"wp-block-prismatic-blocks\"><div class=\"prism-title\">app\/code\/Vendor\/CustomFormRecaptcha\/etc\/module.xml<\/div><pre><code class=\"language-php\" data-line=\"\">&lt;?xml version=&quot;1.0&quot;?&gt;\n&lt;config xmlns:xsi=&quot;http:\/\/www.w3.org\/2001\/XMLSchema-instance&quot;\n       xsi:noNamespaceSchemaLocation=&quot;urn:magento:framework:Module\/etc\/module.xsd&quot;&gt;\n   &lt;module name=&quot;Vendor_CustomFormRecaptcha&quot;\/&gt;\n&lt;\/config&gt;\n<\/code><\/pre><\/div>\n\n\n\n<div class=\"wp-block-prismatic-blocks\"><div class=\"prism-title\">app\/code\/Vendor\/CustomFormRecaptcha\/etc\/frontend\/routes.xml<\/div><pre><code class=\"language-php\" data-line=\"\">&lt;?xml version=&quot;1.0&quot;?&gt;\n&lt;config xmlns:xsi=&quot;http:\/\/www.w3.org\/2001\/XMLSchema-instance&quot;\n        xsi:noNamespaceSchemaLocation=&quot;urn:magento:framework:App\/etc\/routes.xsd&quot;&gt;\n    &lt;router id=&quot;standard&quot;&gt;\n        &lt;route id=&quot;customformrecaptcha&quot; frontName=&quot;customformrecaptcha&quot;&gt;\n            &lt;module name=&quot;Vendor_CustomFormRecaptcha&quot; \/&gt;\n        &lt;\/route&gt;\n    &lt;\/router&gt;\n&lt;\/config&gt;<\/code><\/pre><\/div>\n\n\n\n<div class=\"wp-block-prismatic-blocks\"><div class=\"prism-title\">app\/code\/Vendor\/CustomFormRecaptcha\/Controller\/Index\/Index.php<\/div><pre><code class=\"language-php\" data-line=\"\">&lt;?php\nnamespace Vendor\\CustomFormRecaptcha\\Controller\\Index;\nuse Magento\\Framework\\App\\ActionInterface;\nuse Magento\\Framework\\App\\Action\\Context;\nuse Magento\\Framework\\View\\Result\\PageFactory;\nclass Index implements ActionInterface\n{\n   \/**\n    * @var PageFactory\n    *\/\n   private $resultPageFactory;\n   \/**\n    * @var Context\n    *\/\n   private $context;\n   public function __construct(\n       Context $context,\n       PageFactory $resultPageFactory\n   ) {\n       $this-&gt;context = $context;\n       $this-&gt;resultPageFactory = $resultPageFactory;\n   }\n   public function execute()\n   {\n       return $this-&gt;resultPageFactory-&gt;create();\n   }\n}\n<\/code><\/pre><\/div>\n\n\n\n<div class=\"wp-block-prismatic-blocks\"><div class=\"prism-title\">app\/code\/Vendor\/CustomFormRecaptcha\/view\/frontend\/layout\/customformrecaptcha_index_index.xml<\/div><pre><code class=\"language-php\" data-line=\"\">&lt;?xml version=&quot;1.0&quot;?&gt;\n&lt;page xmlns:xsi=&quot;http:\/\/www.w3.org\/2001\/XMLSchema-instance&quot; xsi:noNamespaceSchemaLocation=&quot;urn:magento:framework:View\/Layout\/etc\/page_configuration.xsd&quot;&gt;\n   &lt;body&gt;\n       &lt;referenceContainer name=&quot;content&quot;&gt;\n           &lt;block class=&quot;Magento\\Framework\\View\\Element\\Template&quot;\n                  name=&quot;customformrecaptcha&quot;\n                  template=&quot;Vendor_CustomFormRecaptcha::form.phtml&quot;\n           \/&gt;\n       &lt;\/referenceContainer&gt;\n   &lt;\/body&gt;\n&lt;\/page&gt;<\/code><\/pre><\/div>\n\n\n\n<div class=\"wp-block-prismatic-blocks\"><div class=\"prism-title\">app\/code\/Vendor\/CustomFormRecaptcha\/view\/frontend\/templates\/form.phtml<\/div><pre><code class=\"language-php\" data-line=\"\">&lt;?php \/** @var \\Magento\\Framework\\View\\Element\\Template $block *\/ ?&gt;\n&lt;form action=&quot;&quot; method=&quot;post&quot;&gt;\n   &lt;div&gt;\n       &lt;label for=&quot;name&quot;&gt;Name:&lt;\/label&gt;\n       &lt;input type=&quot;text&quot; name=&quot;name&quot; id=&quot;name&quot; required\/&gt;\n   &lt;\/div&gt;\n   &lt;div&gt;\n       &lt;label for=&quot;email&quot;&gt;Email:&lt;\/label&gt;\n       &lt;input type=&quot;email&quot; name=&quot;email&quot; id=&quot;email&quot; required\/&gt;\n   &lt;\/div&gt;\n   &lt;div&gt;\n       &lt;button type=&quot;submit&quot;&gt;Submit&lt;\/button&gt;\n   &lt;\/div&gt;\n   &lt;input name=&quot;form_key&quot; type=&quot;hidden&quot; value=&quot;&lt;?php echo $block-&gt;getFormKey(); ?&gt;&quot; \/&gt;\n&lt;\/form&gt;\n<\/code><\/pre><\/div>\n\n\n\n<p class=\"wp-block-paragraph\">After creating the files, run the following commands:<\/p>\n\n\n\n<pre class=\"wp-block-prismatic-blocks\"><code class=\"language-php\" data-line=\"\">php bin\/magento setup:upgrade\nphp bin\/magento setup:di:compile\nphp bin\/magento setup:static-content:deploy\nphp bin\/magento cache:flush\n<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Now we can see our form following the link: https:\/\/your-website-url\/customformrecaptcha\/index\/index  <\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"1206\" height=\"456\" src=\"https:\/\/plumrocket.com\/learn\/wp-content\/uploads\/2025\/01\/add-google-recaptcha-to-custom-form-3.png\" alt=\"Step 2. Create a Custom Extension to Display Your Custom Form\" class=\"wp-image-2282\" srcset=\"https:\/\/plumrocket.com\/learn\/wp-content\/uploads\/2025\/01\/add-google-recaptcha-to-custom-form-3.png 1206w, https:\/\/plumrocket.com\/learn\/wp-content\/uploads\/2025\/01\/add-google-recaptcha-to-custom-form-3-300x113.png 300w, https:\/\/plumrocket.com\/learn\/wp-content\/uploads\/2025\/01\/add-google-recaptcha-to-custom-form-3-1024x387.png 1024w, https:\/\/plumrocket.com\/learn\/wp-content\/uploads\/2025\/01\/add-google-recaptcha-to-custom-form-3-768x290.png 768w\" sizes=\"auto, (max-width: 1206px) 100vw, 1206px\" \/><\/figure>\n<\/div>\n\n\n<h2 id=\"Step 3\" class=\"wp-block-heading\">Step 3. Add the Magento 2 Custom Form to the List of Frontend reCAPTCHA<\/h2>\n\n\n\n<div class=\"wp-block-prismatic-blocks\"><div class=\"prism-title\">Create a file app\/code\/Vendor\/CustomFormRecaptcha\/etc\/adminhtml\/system.xml<\/div><pre><code class=\"language-php\" data-line=\"\">&lt;?xml version=&quot;1.0&quot;?&gt;\n&lt;config xmlns:xsi=&quot;http:\/\/www.w3.org\/2001\/XMLSchema-instance&quot; xsi:noNamespaceSchemaLocation=&quot;urn:magento:module:Magento_Config:etc\/system_file.xsd&quot;&gt;\n   &lt;system&gt;\n       &lt;section id=&quot;recaptcha_frontend&quot;&gt;\n           &lt;group id=&quot;type_for&quot;&gt;\n               &lt;field id=&quot;customformrecaptcha&quot; translate=&quot;label&quot; type=&quot;select&quot; sortOrder=&quot;600&quot; showInDefault=&quot;1&quot; showInWebsite=&quot;1&quot; showInStore=&quot;0&quot; canRestore=&quot;1&quot;&gt;\n                   &lt;label&gt;Enable for Custom Form Recaptcha&lt;\/label&gt;\n                   &lt;source_model&gt;Magento\\ReCaptchaAdminUi\\Model\\OptionSource\\Type&lt;\/source_model&gt;\n               &lt;\/field&gt;\n           &lt;\/group&gt;\n       &lt;\/section&gt;\n   &lt;\/system&gt;\n&lt;\/config&gt;\n<\/code><\/pre><\/div>\n\n\n\n<p class=\"wp-block-paragraph\">Clean magento cache.<br><code class=\"\" data-line=\"\">php bin\/magento cache:flush<\/code><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Go to the Magento Admin panel, navigate to <strong>Stores &gt; Configuration &gt; Security &gt; Google reCAPTCHA &gt; Storefront<\/strong>, and you will see an option to enable Google reCAPTCHA for our custom form.<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"1199\" height=\"491\" src=\"https:\/\/plumrocket.com\/learn\/wp-content\/uploads\/2025\/01\/add-google-recaptcha-to-custom-form-4-1-1.png\" alt=\"Step 3. Add the Magento 2 Custom Form to the List of Frontend reCAPTCHA\" class=\"wp-image-2292\" srcset=\"https:\/\/plumrocket.com\/learn\/wp-content\/uploads\/2025\/01\/add-google-recaptcha-to-custom-form-4-1-1.png 1199w, https:\/\/plumrocket.com\/learn\/wp-content\/uploads\/2025\/01\/add-google-recaptcha-to-custom-form-4-1-1-300x123.png 300w, https:\/\/plumrocket.com\/learn\/wp-content\/uploads\/2025\/01\/add-google-recaptcha-to-custom-form-4-1-1-1024x419.png 1024w, https:\/\/plumrocket.com\/learn\/wp-content\/uploads\/2025\/01\/add-google-recaptcha-to-custom-form-4-1-1-768x315.png 768w\" sizes=\"auto, (max-width: 1199px) 100vw, 1199px\" \/><\/figure>\n\n\n\n<h2 id=\"Step 4\" class=\"wp-block-heading\">Step 4. Display Google reCAPTCHA in the Magento 2 Custom Form<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Create a reCAPTCHA block in the layout file <code class=\"\" data-line=\"\">app\/code\/Vendor\/CustomFormRecaptcha\/view\/frontend\/layout\/customformrecaptcha_index_index.xml<\/code><br>After adding the block, the content of file will be the following:<\/p>\n\n\n\n<pre class=\"wp-block-prismatic-blocks\"><code class=\"language-php\" data-line=\"\">&lt;?xml version=&quot;1.0&quot;?&gt;\n&lt;page xmlns:xsi=&quot;http:\/\/www.w3.org\/2001\/XMLSchema-instance&quot; xsi:noNamespaceSchemaLocation=&quot;urn:magento:framework:View\/Layout\/etc\/page_configuration.xsd&quot;&gt;\n   &lt;body&gt;\n       &lt;referenceContainer name=&quot;content&quot;&gt;\n           &lt;block class=&quot;Magento\\Framework\\View\\Element\\Template&quot;\n                  name=&quot;customformrecaptcha&quot;\n                  template=&quot;Vendor_CustomFormRecaptcha::form.phtml&quot;&gt;\n               &lt;block class=&quot;Magento\\ReCaptchaUi\\Block\\ReCaptcha&quot;\n                      name=&quot;recaptcha&quot;\n                      after=&quot;-&quot;\n                      template=&quot;Magento_ReCaptchaFrontendUi::recaptcha.phtml&quot;\n                      ifconfig=&quot;recaptcha_frontend\/type_for\/customformrecaptcha&quot;&gt;\n                   &lt;arguments&gt;\n                       &lt;argument name=&quot;recaptcha_for&quot; xsi:type=&quot;string&quot;&gt;customformrecaptcha&lt;\/argument&gt;\n                       &lt;argument name=&quot;jsLayout&quot; xsi:type=&quot;array&quot;&gt;\n                           &lt;item name=&quot;components&quot; xsi:type=&quot;array&quot;&gt;\n                               &lt;item name=&quot;recaptcha&quot; xsi:type=&quot;array&quot;&gt;\n                                   &lt;item name=&quot;component&quot; xsi:type=&quot;string&quot;&gt;Magento_ReCaptchaFrontendUi\/js\/reCaptcha&lt;\/item&gt;\n                               &lt;\/item&gt;\n                           &lt;\/item&gt;\n                       &lt;\/argument&gt;\n                   &lt;\/arguments&gt;\n               &lt;\/block&gt;\n           &lt;\/block&gt;\n       &lt;\/referenceContainer&gt;\n   &lt;\/body&gt;\n&lt;\/page&gt;\n<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Now let&#8217;s output the reCAPTCHA block in the form template.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">The content of the file <code class=\"\" data-line=\"\">app\/code\/Vendor\/CustomFormRecaptcha\/view\/frontend\/templates\/form.phtml<\/code> will change to the following:<\/p>\n\n\n\n<pre class=\"wp-block-prismatic-blocks\"><code class=\"language-php\" data-line=\"\">&lt;?php \/** @var \\Magento\\Framework\\View\\Element\\Template $block *\/ ?&gt;\n&lt;form action=&quot;&lt;?= $block-&gt;getUrl(&#039;customformrecaptcha\/index\/post&#039;) ?&gt;&quot; method=&quot;post&quot;&gt;\n   &lt;div&gt;\n       &lt;label for=&quot;name&quot;&gt;Name:&lt;\/label&gt;\n       &lt;input type=&quot;text&quot; name=&quot;name&quot; id=&quot;name&quot; required\/&gt;\n   &lt;\/div&gt;\n   &lt;div&gt;\n       &lt;label for=&quot;email&quot;&gt;Email:&lt;\/label&gt;\n       &lt;input type=&quot;email&quot; name=&quot;email&quot; id=&quot;email&quot; required\/&gt;\n   &lt;\/div&gt;\n   &lt;div&gt;\n       &lt;?php echo $block-&gt;getChildHtml(&#039;recaptcha&#039;); ?&gt;\n   &lt;\/div&gt;\n   &lt;div&gt;\n       &lt;button type=&quot;submit&quot;&gt;Submit&lt;\/button&gt;\n   &lt;\/div&gt;\n   &lt;input name=&quot;form_key&quot; type=&quot;hidden&quot; value=&quot;&lt;?php echo $block-&gt;getFormKey(); ?&gt;&quot; \/&gt;\n&lt;\/form&gt;\n<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Now we can see Google reCAPTCHA on our custom form.<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"1206\" height=\"466\" src=\"https:\/\/plumrocket.com\/learn\/wp-content\/uploads\/2025\/01\/add-google-recaptcha-to-custom-form-5.png\" alt=\"Step 4. Display Google reCAPTCHA in the Magento 2 Custom Form\" class=\"wp-image-2284\" srcset=\"https:\/\/plumrocket.com\/learn\/wp-content\/uploads\/2025\/01\/add-google-recaptcha-to-custom-form-5.png 1206w, https:\/\/plumrocket.com\/learn\/wp-content\/uploads\/2025\/01\/add-google-recaptcha-to-custom-form-5-300x116.png 300w, https:\/\/plumrocket.com\/learn\/wp-content\/uploads\/2025\/01\/add-google-recaptcha-to-custom-form-5-1024x396.png 1024w, https:\/\/plumrocket.com\/learn\/wp-content\/uploads\/2025\/01\/add-google-recaptcha-to-custom-form-5-768x297.png 768w\" sizes=\"auto, (max-width: 1206px) 100vw, 1206px\" \/><\/figure>\n\n\n\n<h2 id=\"Step 5\" class=\"wp-block-heading\">Step 5. Build a Controller to Handle Custom Form Submissions<\/h2>\n\n\n\n<div class=\"wp-block-prismatic-blocks\"><div class=\"prism-title\">Create file app\/code\/Vendor\/CustomFormRecaptcha\/Controller\/Index\/Post.php<\/div><pre><code class=\"language-php\" data-line=\"\">&lt;?php\nnamespace Vendor\\CustomFormRecaptcha\\Controller\\Index;\nuse Magento\\Framework\\App\\Action\\Action;\nuse Magento\\Framework\\App\\Action\\HttpPostActionInterface;\nuse Magento\\Framework\\Controller\\Result\\RedirectFactory;\nuse Magento\\Framework\\Message\\ManagerInterface;\nuse Magento\\Framework\\Exception\\LocalizedException;\nclass Post extends Action implements HttpPostActionInterface\n{\n   protected $resultRedirectFactory;\n   protected $messageManager;\n   public function __construct(\n       \\Magento\\Framework\\App\\Action\\Context $context,\n       RedirectFactory $resultRedirectFactory,\n       ManagerInterface $messageManager\n   ) {\n       parent::__construct($context);\n       $this-&gt;resultRedirectFactory = $resultRedirectFactory;\n       $this-&gt;messageManager = $messageManager;\n   }\n   public function execute()\n   {\n       $postData = $this-&gt;getRequest()-&gt;getPostValue();\n       if ($postData) {\n           try {\n               $this-&gt;_eventManager-&gt;dispatch(&#039;customformrecaptcha_validate_recaptcha&#039;, [&#039;request&#039; =&gt; $this-&gt;getRequest()]);\n               \/\/ Save data\n               $this-&gt;messageManager-&gt;addSuccessMessage(__(&#039;Form submitted successfully.&#039;));\n           } catch (LocalizedException $e) {\n               $this-&gt;messageManager-&gt;addErrorMessage($e-&gt;getMessage());\n           } catch (\\Exception) {\n               $this-&gt;messageManager-&gt;addErrorMessage(__(&#039;An error occurred: %1&#039;, $e-&gt;getMessage()));\n           }\n       } else {\n           $this-&gt;messageManager-&gt;addErrorMessage(__(&#039;No data received.&#039;));\n       }\n       return $this-&gt;resultRedirectFactory-&gt;create()-&gt;setPath(&#039;*\/*\/&#039;);\n   }\n}\n<\/code><\/pre><\/div>\n\n\n\n<h2 id=\"Step 6\" class=\"wp-block-heading\">Step 6. Create an Observer to Validate Google reCAPTCHA for the Custom Form in Magento 2<\/h2>\n\n\n\n<div class=\"wp-block-prismatic-blocks\"><div class=\"prism-title\">Create file: app\/code\/CustomFormRecaptcha\/Module\/etc\/frontend\/events.xml<\/div><pre><code class=\"language-php\" data-line=\"\">&lt;?xml version=&quot;1.0&quot;?&gt;\n&lt;config xmlns:xsi=&quot;http:\/\/www.w3.org\/2001\/XMLSchema-instance&quot; xsi:noNamespaceSchemaLocation=&quot;urn:magento:framework\/Event\/etc\/events.xsd&quot;&gt;\n   &lt;event name=&quot;customformrecaptcha_validate_recaptcha&quot;&gt;\n       &lt;observer name=&quot;validate_recaptcha&quot; instance=&quot;Vendor\\CustomFormRecaptcha\\Observer\\ValidateRecaptcha&quot; \/&gt;\n   &lt;\/event&gt;\n&lt;\/config&gt;\n<\/code><\/pre><\/div>\n\n\n\n<div class=\"wp-block-prismatic-blocks\"><div class=\"prism-title\">Create file: app\/code\/Vendor\/CustomFormRecaptcha\/Observer\/ValidateRecaptcha.php<\/div><pre><code class=\"language-php\" data-line=\"\">\n&lt;?php\nnamespace Vendor\\CustomFormRecaptcha\\Observer;\nuse Magento\\Framework\\Event\\Observer;\nuse Magento\\Framework\\Event\\ObserverInterface;\nuse Magento\\Framework\\Exception\\InputException;\nuse Magento\\Framework\\Exception\\LocalizedException;\nuse Magento\\Framework\\ObjectManagerInterface;\nuse Magento\\ReCaptchaUi\\Model\\IsCaptchaEnabledInterface;\nclass ValidateRecaptcha implements ObserverInterface\n{\n   \/**\n    * @var IsCaptchaEnabledInterface\n    *\/\n   private $isCaptchaEnabled;\n   \/**\n    * @var ObjectManagerInterface\n    *\/\n   private $objectManager;\n   public function __construct(\n       IsCaptchaEnabledInterface $isCaptchaEnabled,\n       ObjectManagerInterface $objectManager,\n   ) {\n       $this-&gt;isCaptchaEnabled = $isCaptchaEnabled;\n       $this-&gt;objectManager = $objectManager;\n   }\n   \/**\n    * @throws InputException\n    *\/\n   public function execute(Observer $observer)\n   {\n       $key = &#039;customformrecaptcha&#039;;\n       $request = $observer-&gt;getRequest();\n       if ($this-&gt;isCaptchaEnabled-&gt;isCaptchaEnabledFor($key)) {\n           $validationConfigResolver = $this-&gt;objectManager-&gt;get(\n               \\Magento\\ReCaptchaUi\\Model\\ValidationConfigResolverInterface::class\n           );\n           $captchaResponseResolver = $this-&gt;objectManager-&gt;get(\n               \\Magento\\ReCaptchaUi\\Model\\CaptchaResponseResolverInterface::class\n           );\n           $captchaValidator = $this-&gt;objectManager-&gt;get(\n               \\Magento\\ReCaptchaValidationApi\\Api\\ValidatorInterface::class\n           );\n           $validationConfig = $validationConfigResolver-&gt;get($key);\n           try {\n               $reCaptchaResponse = $captchaResponseResolver-&gt;resolve($request);\n           } catch (InputException $e) {\n               throw new LocalizedException(__(&#039;Please complete the reCAPTCHA validation.&#039;));\n           }\n           $validationResult = $captchaValidator-&gt;isValid($reCaptchaResponse, $validationConfig);\n           if (false === $validationResult-&gt;isValid()) {\n               throw new LocalizedException(__(&#039;reCAPTCHA validation failed. Please try again.&#039;));\n           }\n       }\n   }\n}\n<\/code><\/pre><\/div>\n\n\n\n<h2 class=\"wp-block-heading\">Conclusion<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">By taking these simple steps, you improve not just the functionality of your website but also the confidence your customers have in your brand. Keep optimizing and securing your store to provide the best possible experience for your users.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Frequently Asked Questions (FAQ)<\/h2>\n\n\n\n<div class=\"schema-faq wp-block-yoast-faq-block\"><div class=\"schema-faq-section\" id=\"faq-question-1787130876253\"><strong class=\"schema-faq-question\"><strong>Why doesn&#8217;t reCAPTCHA appear on my custom form?<\/strong><\/strong> <p class=\"schema-faq-answer\">Work through it in this order. First, confirm your form&#8217;s field is actually set at <strong>Stores > Configuration > Security > Google reCAPTCHA Storefront > Storefront<\/strong>. That field only shows up after the <code class=\"\" data-line=\"\">system.xml<\/code> from Step 3 is in place and the cache is flushed. <br>Second, check that the <code class=\"\" data-line=\"\">ifconfig<\/code> value on your reCAPTCHA block matches the field ID character for character: <code class=\"\" data-line=\"\">recaptcha_frontend\/type_for\/customformrecaptcha<\/code>. <br>Third, flush the cache and redeploy static content. Most of the time it&#8217;s a stale cache or a one-character mismatch between the two.<\/p> <\/div> <div class=\"schema-faq-section\" id=\"faq-question-1787130915900\"><strong class=\"schema-faq-question\">The form submits fine, but reCAPTCHA never blocks anything. What&#8217;s wrong?<\/strong> <p class=\"schema-faq-answer\">Two usual suspects. Your <code class=\"\" data-line=\"\">events.xml<\/code> has to sit at <code class=\"\" data-line=\"\">app\/code\/Vendor\/CustomFormRecaptcha\/etc\/frontend\/events.xml<\/code>. Get that path wrong and the observer never registers, so validation silently never runs and everything looks like it&#8217;s working. The other suspect is the form key. Magento validates the form key on every frontend POST, so if that hidden input renders empty you get bounced before the observer ever fires. Use <code class=\"\" data-line=\"\">$block-&gt;getBlockHtml(&#039;formkey&#039;)<\/code> in your template. <code class=\"\" data-line=\"\">$block-&gt;getFormKey()<\/code> doesn&#8217;t exist on <code class=\"\" data-line=\"\">Magento\\Framework\\View\\Element\\Template<\/code> and returns nothing.<\/p> <\/div> <div class=\"schema-faq-section\" id=\"faq-question-1787130941567\"><strong class=\"schema-faq-question\">reCAPTCHA validation fails for everyone, including real customers. Why?<\/strong> <p class=\"schema-faq-answer\">Check <code class=\"\" data-line=\"\">php.ini<\/code> first. Adobe requires <code class=\"\" data-line=\"\">allow_url_fopen = 1<\/code> before Google reCAPTCHA can work at all, and on locked-down hosting it&#8217;s often off. Without it, Magento can&#8217;t reach Google&#8217;s verification endpoint and every submission fails.<\/p> <\/div> <div class=\"schema-faq-section\" id=\"faq-question-1787130968285\"><strong class=\"schema-faq-question\">Which reCAPTCHA type should I use for a custom form?<\/strong> <p class=\"schema-faq-answer\">Start with v3 Invisible. It scores traffic in the background with nothing for the customer to click, which matters on a form you&#8217;re asking people to fill in anyway. Google itself no longer recommends checkbox keys, on the grounds that they add friction without meaningfully improving accuracy. Use v2 only if you have a specific reason to show a challenge. Whichever you pick, the type selected in Magento must match the type of the key you generated, or validation fails with a confusing error.<\/p> <\/div> <div class=\"schema-faq-section\" id=\"faq-question-1787130980805\"><strong class=\"schema-faq-question\">Does this work on a Hyv\u00e4 storefront?<\/strong> <p class=\"schema-faq-answer\">The server side does. Steps 3, 5 and 6 are unchanged. Step 4 is not: Hyv\u00e4 doesn&#8217;t load RequireJS or Knockout, so the <code class=\"\" data-line=\"\">jsLayout<\/code> component renders nothing. Hyv\u00e4 ships its own blocks for this, <code class=\"\" data-line=\"\">recaptcha_validation<\/code>, <code class=\"\" data-line=\"\">recaptcha_validation_invisible<\/code> and <code class=\"\" data-line=\"\">recaptcha_validation_recaptcha<\/code>. Assign the one matching your reCAPTCHA version as a child of your form block using the alias <code class=\"\" data-line=\"\">recaptcha_validation<\/code>.<\/p> <\/div> <div class=\"schema-faq-section\" id=\"faq-question-1787130999722\"><strong class=\"schema-faq-question\">Does adding reCAPTCHA to more forms cost anything?<\/strong> <p class=\"schema-faq-answer\">Once your keys are managed in a Google Cloud project, the free allowance is 10,000 assessments per month, and you&#8217;re billed past that. Every protected submission counts against it. Worth checking your volume before you add reCAPTCHA to a high-traffic form like newsletter signup.<\/p> <\/div> <\/div>\n","protected":false},"excerpt":{"rendered":"<p>Google reCAPTCHA helps protect websites from spam, bot attacks, and other automated form submissions. <\/p>\n<p>Adding reCAPTCHA to your Magento 2 custom forms adds an essential layer of security, ensuring only genuine user interactions are processed by your site.<\/p>\n","protected":false},"author":7,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_monsterinsights_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0,"footnotes":""},"categories":[144],"tags":[],"class_list":["post-2264","post","type-post","status-publish","format-standard","hentry","category-magento-backend-dev-guide","entry"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.9 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>How to Add Google reCAPTCHA to Custom Form\u200b in Magento 2<\/title>\n<meta name=\"description\" content=\"Learn how to add Google reCAPTCHA to custom forms in Magento 2 to protect your site from spam and bots with this step-by-step guide.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/plumrocket.com\/learn\/magento-2-add-google-recaptcha\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"How to Add Google reCAPTCHA to Custom Form\u200b in Magento 2\" \/>\n<meta property=\"og:description\" content=\"Learn how to add Google reCAPTCHA to custom forms in Magento 2 to protect your site from spam and bots with this step-by-step guide.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/plumrocket.com\/learn\/magento-2-add-google-recaptcha\" \/>\n<meta property=\"og:site_name\" content=\"Magento Tutorials for Beginners &amp; Professionals\" \/>\n<meta property=\"article:published_time\" content=\"2025-01-10T11:47:51+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2026-08-19T09:17:50+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/plumrocket.com\/learn\/wp-content\/uploads\/2025\/01\/add-google-recaptcha-to-custom-form-1.png\" \/>\n\t<meta property=\"og:image:width\" content=\"1600\" \/>\n\t<meta property=\"og:image:height\" content=\"600\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/png\" \/>\n<meta name=\"author\" content=\"Volodymyr Holovatskiy\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Volodymyr Holovatskiy\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"6 minutes\" \/>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"How to Add Google reCAPTCHA to Custom Form\u200b in Magento 2","description":"Learn how to add Google reCAPTCHA to custom forms in Magento 2 to protect your site from spam and bots with this step-by-step guide.","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/plumrocket.com\/learn\/magento-2-add-google-recaptcha","og_locale":"en_US","og_type":"article","og_title":"How to Add Google reCAPTCHA to Custom Form\u200b in Magento 2","og_description":"Learn how to add Google reCAPTCHA to custom forms in Magento 2 to protect your site from spam and bots with this step-by-step guide.","og_url":"https:\/\/plumrocket.com\/learn\/magento-2-add-google-recaptcha","og_site_name":"Magento Tutorials for Beginners &amp; Professionals","article_published_time":"2025-01-10T11:47:51+00:00","article_modified_time":"2026-08-19T09:17:50+00:00","og_image":[{"width":1600,"height":600,"url":"https:\/\/plumrocket.com\/learn\/wp-content\/uploads\/2025\/01\/add-google-recaptcha-to-custom-form-1.png","type":"image\/png"}],"author":"Volodymyr Holovatskiy","twitter_card":"summary_large_image","twitter_misc":{"Written by":"Volodymyr Holovatskiy","Est. reading time":"6 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/plumrocket.com\/learn\/magento-2-add-google-recaptcha#article","isPartOf":{"@id":"https:\/\/plumrocket.com\/learn\/magento-2-add-google-recaptcha"},"author":{"name":"Volodymyr Holovatskiy","@id":"https:\/\/plumrocket.com\/learn\/#\/schema\/person\/161911374678c2f70335dd5a1efac69f"},"headline":"How to Add Google reCAPTCHA to Custom Form\u200b in Magento 2","datePublished":"2025-01-10T11:47:51+00:00","dateModified":"2026-08-19T09:17:50+00:00","mainEntityOfPage":{"@id":"https:\/\/plumrocket.com\/learn\/magento-2-add-google-recaptcha"},"wordCount":1028,"commentCount":0,"image":{"@id":"https:\/\/plumrocket.com\/learn\/magento-2-add-google-recaptcha#primaryimage"},"thumbnailUrl":"https:\/\/plumrocket.com\/learn\/wp-content\/uploads\/2025\/01\/add-google-recaptcha-to-custom-form-1.png","articleSection":["Magento Backend Development"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/plumrocket.com\/learn\/magento-2-add-google-recaptcha#respond"]}]},{"@type":["WebPage","FAQPage"],"@id":"https:\/\/plumrocket.com\/learn\/magento-2-add-google-recaptcha","url":"https:\/\/plumrocket.com\/learn\/magento-2-add-google-recaptcha","name":"How to Add Google reCAPTCHA to Custom Form\u200b in Magento 2","isPartOf":{"@id":"https:\/\/plumrocket.com\/learn\/#website"},"primaryImageOfPage":{"@id":"https:\/\/plumrocket.com\/learn\/magento-2-add-google-recaptcha#primaryimage"},"image":{"@id":"https:\/\/plumrocket.com\/learn\/magento-2-add-google-recaptcha#primaryimage"},"thumbnailUrl":"https:\/\/plumrocket.com\/learn\/wp-content\/uploads\/2025\/01\/add-google-recaptcha-to-custom-form-1.png","datePublished":"2025-01-10T11:47:51+00:00","dateModified":"2026-08-19T09:17:50+00:00","author":{"@id":"https:\/\/plumrocket.com\/learn\/#\/schema\/person\/161911374678c2f70335dd5a1efac69f"},"description":"Learn how to add Google reCAPTCHA to custom forms in Magento 2 to protect your site from spam and bots with this step-by-step guide.","breadcrumb":{"@id":"https:\/\/plumrocket.com\/learn\/magento-2-add-google-recaptcha#breadcrumb"},"mainEntity":[{"@id":"https:\/\/plumrocket.com\/learn\/magento-2-add-google-recaptcha#faq-question-1787130876253"},{"@id":"https:\/\/plumrocket.com\/learn\/magento-2-add-google-recaptcha#faq-question-1787130915900"},{"@id":"https:\/\/plumrocket.com\/learn\/magento-2-add-google-recaptcha#faq-question-1787130941567"},{"@id":"https:\/\/plumrocket.com\/learn\/magento-2-add-google-recaptcha#faq-question-1787130968285"},{"@id":"https:\/\/plumrocket.com\/learn\/magento-2-add-google-recaptcha#faq-question-1787130980805"},{"@id":"https:\/\/plumrocket.com\/learn\/magento-2-add-google-recaptcha#faq-question-1787130999722"}],"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/plumrocket.com\/learn\/magento-2-add-google-recaptcha"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/plumrocket.com\/learn\/magento-2-add-google-recaptcha#primaryimage","url":"https:\/\/plumrocket.com\/learn\/wp-content\/uploads\/2025\/01\/add-google-recaptcha-to-custom-form-1.png","contentUrl":"https:\/\/plumrocket.com\/learn\/wp-content\/uploads\/2025\/01\/add-google-recaptcha-to-custom-form-1.png","width":1600,"height":600},{"@type":"BreadcrumbList","@id":"https:\/\/plumrocket.com\/learn\/magento-2-add-google-recaptcha#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Learn","item":"https:\/\/plumrocket.com\/learn"},{"@type":"ListItem","position":2,"name":"How to Add Google reCAPTCHA to Custom Form\u200b in Magento 2"}]},{"@type":"WebSite","@id":"https:\/\/plumrocket.com\/learn\/#website","url":"https:\/\/plumrocket.com\/learn\/","name":"Magento Tutorials for Beginners &amp; Professionals","description":"Plumrocket Inc","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/plumrocket.com\/learn\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Person","@id":"https:\/\/plumrocket.com\/learn\/#\/schema\/person\/161911374678c2f70335dd5a1efac69f","name":"Volodymyr Holovatskiy","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/plumrocket.com\/learn\/wp-content\/uploads\/2024\/10\/avatar_user_7_1729774175-96x96.png","url":"https:\/\/plumrocket.com\/learn\/wp-content\/uploads\/2024\/10\/avatar_user_7_1729774175-96x96.png","contentUrl":"https:\/\/plumrocket.com\/learn\/wp-content\/uploads\/2024\/10\/avatar_user_7_1729774175-96x96.png","caption":"Volodymyr Holovatskiy"},"description":"Magento 2 developer passionate about creating efficient and functional ecommerce solutions. Loves skiing and hiking in the mountains, finding inspiration for new ideas and solutions in web development.","url":"https:\/\/plumrocket.com\/learn\/author\/volodymyr-holovatskiy"},{"@type":"Question","@id":"https:\/\/plumrocket.com\/learn\/magento-2-add-google-recaptcha#faq-question-1787130876253","position":1,"url":"https:\/\/plumrocket.com\/learn\/magento-2-add-google-recaptcha#faq-question-1787130876253","name":"Why doesn't reCAPTCHA appear on my custom form?","answerCount":1,"acceptedAnswer":{"@type":"Answer","text":"Work through it in this order. First, confirm your form's field is actually set at <strong>Stores > Configuration > Security > Google reCAPTCHA Storefront > Storefront<\/strong>. That field only shows up after the system.xml from Step 3 is in place and the cache is flushed. <br>Second, check that the ifconfig value on your reCAPTCHA block matches the field ID character for character: recaptcha_frontend\/type_for\/customformrecaptcha. <br>Third, flush the cache and redeploy static content. Most of the time it's a stale cache or a one-character mismatch between the two.","inLanguage":"en-US"},"inLanguage":"en-US"},{"@type":"Question","@id":"https:\/\/plumrocket.com\/learn\/magento-2-add-google-recaptcha#faq-question-1787130915900","position":2,"url":"https:\/\/plumrocket.com\/learn\/magento-2-add-google-recaptcha#faq-question-1787130915900","name":"The form submits fine, but reCAPTCHA never blocks anything. What's wrong?","answerCount":1,"acceptedAnswer":{"@type":"Answer","text":"Two usual suspects. Your events.xml has to sit at app\/code\/Vendor\/CustomFormRecaptcha\/etc\/frontend\/events.xml. Get that path wrong and the observer never registers, so validation silently never runs and everything looks like it's working. The other suspect is the form key. Magento validates the form key on every frontend POST, so if that hidden input renders empty you get bounced before the observer ever fires. Use $block->getBlockHtml('formkey') in your template. $block->getFormKey() doesn't exist on Magento\\Framework\\View\\Element\\Template and returns nothing.","inLanguage":"en-US"},"inLanguage":"en-US"},{"@type":"Question","@id":"https:\/\/plumrocket.com\/learn\/magento-2-add-google-recaptcha#faq-question-1787130941567","position":3,"url":"https:\/\/plumrocket.com\/learn\/magento-2-add-google-recaptcha#faq-question-1787130941567","name":"reCAPTCHA validation fails for everyone, including real customers. Why?","answerCount":1,"acceptedAnswer":{"@type":"Answer","text":"Check php.ini first. Adobe requires allow_url_fopen = 1 before Google reCAPTCHA can work at all, and on locked-down hosting it's often off. Without it, Magento can't reach Google's verification endpoint and every submission fails.","inLanguage":"en-US"},"inLanguage":"en-US"},{"@type":"Question","@id":"https:\/\/plumrocket.com\/learn\/magento-2-add-google-recaptcha#faq-question-1787130968285","position":4,"url":"https:\/\/plumrocket.com\/learn\/magento-2-add-google-recaptcha#faq-question-1787130968285","name":"Which reCAPTCHA type should I use for a custom form?","answerCount":1,"acceptedAnswer":{"@type":"Answer","text":"Start with v3 Invisible. It scores traffic in the background with nothing for the customer to click, which matters on a form you're asking people to fill in anyway. Google itself no longer recommends checkbox keys, on the grounds that they add friction without meaningfully improving accuracy. Use v2 only if you have a specific reason to show a challenge. Whichever you pick, the type selected in Magento must match the type of the key you generated, or validation fails with a confusing error.","inLanguage":"en-US"},"inLanguage":"en-US"},{"@type":"Question","@id":"https:\/\/plumrocket.com\/learn\/magento-2-add-google-recaptcha#faq-question-1787130980805","position":5,"url":"https:\/\/plumrocket.com\/learn\/magento-2-add-google-recaptcha#faq-question-1787130980805","name":"Does this work on a Hyv\u00e4 storefront?","answerCount":1,"acceptedAnswer":{"@type":"Answer","text":"The server side does. Steps 3, 5 and 6 are unchanged. Step 4 is not: Hyv\u00e4 doesn't load RequireJS or Knockout, so the jsLayout component renders nothing. Hyv\u00e4 ships its own blocks for this, recaptcha_validation, recaptcha_validation_invisible and recaptcha_validation_recaptcha. Assign the one matching your reCAPTCHA version as a child of your form block using the alias recaptcha_validation.","inLanguage":"en-US"},"inLanguage":"en-US"},{"@type":"Question","@id":"https:\/\/plumrocket.com\/learn\/magento-2-add-google-recaptcha#faq-question-1787130999722","position":6,"url":"https:\/\/plumrocket.com\/learn\/magento-2-add-google-recaptcha#faq-question-1787130999722","name":"Does adding reCAPTCHA to more forms cost anything?","answerCount":1,"acceptedAnswer":{"@type":"Answer","text":"Once your keys are managed in a Google Cloud project, the free allowance is 10,000 assessments per month, and you're billed past that. Every protected submission counts against it. Worth checking your volume before you add reCAPTCHA to a high-traffic form like newsletter signup.","inLanguage":"en-US"},"inLanguage":"en-US"}]}},"_links":{"self":[{"href":"https:\/\/plumrocket.com\/learn\/wp-json\/wp\/v2\/posts\/2264","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/plumrocket.com\/learn\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/plumrocket.com\/learn\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/plumrocket.com\/learn\/wp-json\/wp\/v2\/users\/7"}],"replies":[{"embeddable":true,"href":"https:\/\/plumrocket.com\/learn\/wp-json\/wp\/v2\/comments?post=2264"}],"version-history":[{"count":15,"href":"https:\/\/plumrocket.com\/learn\/wp-json\/wp\/v2\/posts\/2264\/revisions"}],"predecessor-version":[{"id":3044,"href":"https:\/\/plumrocket.com\/learn\/wp-json\/wp\/v2\/posts\/2264\/revisions\/3044"}],"wp:attachment":[{"href":"https:\/\/plumrocket.com\/learn\/wp-json\/wp\/v2\/media?parent=2264"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/plumrocket.com\/learn\/wp-json\/wp\/v2\/categories?post=2264"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/plumrocket.com\/learn\/wp-json\/wp\/v2\/tags?post=2264"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}