default.xml from theme
<?xml version="1.0"?>
<!--
/**
* MageSpecialist
*
* NOTICE OF LICENSE
*
* This source file is subject to the Open Software License (OSL 3.0)
* that is bundled with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://opensource.org/licenses/osl-3.0.php
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to [email protected] so we can send you a copy immediately.
*
* @category MSP
* @package MSP_ReCaptcha
* @copyright Copyright (c) 2017 Skeeller srl (http://www.magespecialist.it)
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
*/
-->
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
<body>
<referenceContainer name="form.additional.persistent">
<block class="Magento\ReCaptchaUi\Block\ReCaptcha"
name="mini-recaptcha"
after="-"
template="Magento_ReCaptchaFrontendUi::recaptcha.phtml"
ifconfig="recaptcha_frontend/type_for/customer_login">
<arguments>
<argument name="recaptcha_for" xsi:type="string">customer_login</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 name="reCaptchaId" xsi:type="string">msp-recaptcha-mini-login</item>
<item name="zone" xsi:type="string">login</item>
</item>
</item>
</argument>
</arguments>
</block>
</referenceContainer>
</body>
</page>
default.xml from HCaptcha
<?xml version="1.0"?>
<!--
/**
* Copyright © Grasch, Inc. All rights reserved.
*/
-->
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
<body>
<referenceBlock name="recaptcha-newsletter" class="Grasch\HCaptcha\Block\HCaptchaNewsletter">
<arguments>
<argument name="hcaptcha_for" xsi:type="string">newsletter</argument>
</arguments>
</referenceBlock>
<referenceContainer name="form.additional.persistent">
<referenceBlock name="mini-recaptcha" remove="true"/>
<block class="Grasch\HCaptcha\Block\HCaptcha"
name="mini-hcaptcha"
after="-"
template="Grasch_HCaptcha::hcaptcha.phtml"
ifconfig="recaptcha_frontend/type_for/customer_login"
>
<arguments>
<argument name="hcaptcha_for" xsi:type="string">customer_login</argument>
<argument name="jsLayout" xsi:type="array">
<item name="components" xsi:type="array">
<item name="hcaptcha" xsi:type="array">
<item name="component" xsi:type="string">Grasch_HCaptcha/js/hCaptcha</item>
<item name="hCaptchaId" xsi:type="string">hcaptcha-mini-login</item>
<item name="zone" xsi:type="string">login</item>
</item>
</item>
</argument>
</arguments>
</block>
</referenceContainer>
</body>
</page>
When ReCAPTCHA is configured for customer login, it only appears on customer/account/login page and fails to appear in custom login modal. It will only appear if I remove the hCaptcha block in hcaptcha's xml completely, otherwise it will try to load hCaptcha configuration for some reason (indicator is hcaptcha messages about wrong sitekey)
Any ideas on how to fix it?
HCaptcha is downloaded from this repository
1 Answer 1
Ensure that each captcha block is only declared in its respective layout XML using ifconfig, to prevent them from overriding each other.
default.xml (theme):
<referenceContainer name="form.additional.persistent">
<block class="Magento\ReCaptchaUi\Block\ReCaptcha"
name="mini-recaptcha"
after="-"
template="Magento_ReCaptchaFrontendUi::recaptcha.phtml"
ifconfig="recaptcha_frontend/type_for/customer_login">
<arguments>
<argument name="recaptcha_for" xsi:type="string">customer_login</argument>
<argument name="jsLayout" xsi:type="array"> ... </argument>
</arguments>
</block>
Make sure hCaptcha's XML also includes a strict ifconfig test (usually ifconfig="hcaptcha/..."). This ensures that hCaptcha’s JavaScript is only loaded when hCaptcha is actually active.
Remove Conflicting hCaptcha XML (When Using reCAPTCHA Only) If you don’t intend to use hCaptcha, simply remove or comment out the entire hCaptcha block from its layout XML. This stops Magento from ever trying to inject that configuration, eliminating conflicts.
-
hcaptcha in this case is just another recaptcha type if you really look at the implementation, so recaptcha_frontend is valid since it's added to the same menu. I need to figure out why it tries to load scripts and configuration when it's not enabled in the admin. i also have a module that swaps captchas based on customer country from IP/session, but that's another topic...Dramorian– Dramorian2025年06月23日 22:28:52 +00:00Commented Jun 23 at 22:28