ReCaptchaV3 validation does not work with submitVar property

MODX 3.2.0-pl
FormIt 5.1.1-pl
GoodNews 2.0.0-alpha2
ReCaptchaV2 3.2.2-pl

I have problems to get a form submission working with ReCaptcha validation and a submitVar property. When I do not use a submitVar in a FormIt Snippet, the ReCaptcha validation works as expected.

Unfortunately, submitVar is mandatory for GoodNews, so no newsletter subscription is possible with ReCaptcha validation at the moment.

Does anyone else have this problem too?

I can provide more information or logs when you guide me which log you need.

Thank you for your support!

[[!GoodNewsSubscription?
&preHooks=`recaptchav3`
&activation=`1`
&activationEmailSubject=`...`
&activationEmailTpl=`...`
&activationResourceId=`...`
&unsubscribeResourceId=`...`
&profileResourceId=`...`
&sendSubscriptionEmail=`1`
&reSubscriptionEmailSubject=`...`
&reSubscriptionEmailTpl=`...`
&emailField=`email-newsletter`
&usernameField=`name-newsletter`
&successMsg=`...`
&defaultGroups=`1`
&submitVar=`newsletterform`
&recaptchav3.token_key=`token-newsletter`
&recaptchav3.action_key=`action-newsletter`
]]

...
<input type="submit" role="button" class="btn btn-secondary" id="submit-newsletter" name="newsletterform" value="...">
...
[[!FormIt?
&hooks=`recaptchav3,spam,email`
&formName=`contact`
&clearFieldsOnSuccess=`1`
&store=`0`
&spamEmailFields=`email-contact`
&emailTpl=`...`
&emailSubject=`...`
&emailFrom=`...`
&emailFromName=`...`
&emailReplyTo=`...`
&emailReplyToName=`...`
&emailTo=`...`
&emailCC=`...`
&emailCCName=`...`
&validate=`nospam:blank,
name-contact:required
,surname-contact:required
,email-contact:email:required
,comment-contact:required
,confirmation-contact:required`
&successMessage=`...`
&validationErrorMessage=`...`
&submitVar=`submit-contact-form`
&recaptchav3.token_key=`token-contact`
&recaptchav3.action_key=`action-contact`
]]

...
<input type="submit" role="button" id="submit-contact" name="submit-contact-form" value="..." class="btn btn-secondary">
...

hi !

i had it working by adding these hidden fields in the form :slight_smile:

<input type="hidden" name="goodnews-subscription" value="1"> <input type="hidden" name="[[++recaptchav3.action_key]]" value="goodnewssubscriptionbtn"> <input type="hidden" name="[[++recaptchav3.token_key]]">

and a separate script on the page :

Hi @troubadour,

Thank you for your response.

The action-key and the token-key is added by the recaptcha chunk. The token will be set when the submit button is clicked.

<input type="hidden" name="token-newsletter">
<input type="hidden" name="action-newsletter" value="newsletterform">

Adding <input type="hidden" name="goodnews-subscription" value="1"> does not change anything.

It seems, that you forgot to add the script you mentioned in your post.

The main question for me is, why ReCaptcha does not work anymore when you use submitVar?

recaptcha works with submitVar on my website.

sorry here is the script :slight_smile:

<script>
 grecaptcha.ready(() => {
    document.querySelectorAll('form').forEach((form) => {
        form.onmouseenter = (event) => {
            const action = event.target.querySelector('[name="[[++recaptchav3.action_key]]"]');
            grecaptcha.execute('[[++recaptchav3.site_key]]', {action: action.value}).then((token) => {
                action.nextElementSibling.value = token;
            });
        }
    });
});
</script>

in GoodNewsSubscription snippet did you add ?

&preHooks=`recaptchav3`
&submitVar=`goodnews-subscription`

Thank you for some hints. submitVar haven’t worked due to my script and the way I submit the form. I have an EventListener for submit and send the form via JavaScript. Due to that, the button with the submit name is not included in the payload.

All FormIt forms work now! :heart_eyes:

However, the GoodNews subscription still isn’t working. In have the following lines in the error log:

[2026-04-08 08:13:57] (ERROR @ .../core/cache/includes/elements/modx/revolution/modsnippet/41.include.cache.php : 48) PHP warning: Undefined property: Bitego\GoodNews\Subscription\Hooks::$formit
[2026-04-08 08:13:57] (ERROR @ .../core/cache/includes/elements/modx/revolution/modsnippet/41.include.cache.php : 50) PHP warning: Undefined property: Bitego\GoodNews\Subscription\Hooks::$login
[2026-04-08 08:13:57] (ERROR @ .../core/components/goodnews/src/Subscription/Hooks.php : 203) PHP warning: Undefined array key "recaptchav3_error"
[2026-04-08 08:13:57] (ERROR @ .../core/components/goodnews/src/Subscription/Hooks.php : 153) PHP warning: Undefined array key "recaptchav3"

i forgot that code. put it in your header :

<script src="https://www.google.com/recaptcha/api.js?render=[[++recaptchav3.site_key]]&hl=[[++cultureKey]]"></script>

i had found these informations here : A Guide to Recaptcha V3 for MODX CMS

I found the issue with the extra ReCaptchaV2 and GoodNews. The hook of ReCaptchaV2 is not implemented for GoodNews and its configuration structure. ReCaptchaV2 is just valid for formit and login.

Here is the relevant part of the snippet:

// Options
$hookConfig = [];
if ($hook->formit) {
    $hookConfig = $hook->formit->config;
} elseif ($hook->login) {
    $hookConfig = $hook->login->controller->config;
}
foreach ($hookConfig as $k => $v) {
    if (strpos($k, 'recaptchav3.') === 0) {
        $k = substr($k, 12);
        $props[$k] = $v;
    }
}

I extended it with subscription for GoodNews:

// Options
$hookConfig = [];
if (isset($hook->formit)) {
    $hookConfig = $hook->formit->config;
} elseif (isset($hook->login)) {
    $hookConfig = $hook->login->controller->config;
} elseif (isset($hook->subscription)) {
    $hookConfig = $hook->subscription->config;
}
foreach ($hookConfig as $k => $v) {
    if (strpos($k, 'recaptchav3.') === 0) {
        $k = substr($k, 12);
        $props[$k] = $v;
    }
}

I created a Pull Request to fix this: #64 Update recaptchav3.snippet.php to be able to use it with GoodNews by rabesocke · Pull Request #65 · sepiariver/recaptchav2 · GitHub