{"id":39448385,"url":"https://github.com/globalia/craft-recaptcha-v3","last_synced_at":"2026-01-18T04:26:56.781Z","repository":{"id":78598308,"uuid":"265674830","full_name":"globalia/craft-recaptcha-v3","owner":"globalia","description":"A Craft CMS 2 reCAPTCHA v3 plugin.","archived":false,"fork":false,"pushed_at":"2024-01-10T15:35:27.000Z","size":19,"stargazers_count":2,"open_issues_count":1,"forks_count":0,"subscribers_count":3,"default_branch":"master","last_synced_at":"2024-01-10T17:56:00.453Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/globalia.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null}},"created_at":"2020-05-20T20:05:14.000Z","updated_at":"2023-12-27T10:09:22.000Z","dependencies_parsed_at":"2023-05-12T06:15:54.119Z","dependency_job_id":null,"html_url":"https://github.com/globalia/craft-recaptcha-v3","commit_stats":null,"previous_names":[],"tags_count":0,"template":null,"template_full_name":null,"purl":"pkg:github/globalia/craft-recaptcha-v3","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/globalia%2Fcraft-recaptcha-v3","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/globalia%2Fcraft-recaptcha-v3/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/globalia%2Fcraft-recaptcha-v3/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/globalia%2Fcraft-recaptcha-v3/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/globalia","download_url":"https://codeload.github.com/globalia/craft-recaptcha-v3/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/globalia%2Fcraft-recaptcha-v3/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28529558,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-01-18T00:39:45.795Z","status":"online","status_checked_at":"2026-01-18T02:00:07.578Z","response_time":98,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2026-01-18T04:26:56.585Z","updated_at":"2026-01-18T04:26:56.764Z","avatar_url":"https://github.com/globalia.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# reCAPTCHA v3\n\nAdds reCAPTCHA capability to Craft CMS 2 forms.\n\n## How to use\n\n### There is a little example snippet\n\nAdd this code in your \\\u003cform\\\u003e :\n```\n{% if craft.plugins.getPlugin('recaptchaV3', true) and craft.recaptchaV3.hasRecaptchaKeys %}\n    \u003cinput type=\"hidden\" data-action=\"contact\" name=\"g-recaptcha-response\"\u003e\n{% endif %}\n```\n\nThe `data-action=\"contact\"` attribute will be the action sent to reCAPTCHA. It's useful to know \nfrom which form the data is coming from. In this case, this is the Contact form.\n\nIn your \\\u003chead\\\u003e :\n\n** Remove `and renderReCaptcha | default` if you want to load reCAPTCHA on all pages)\n```\n{% if craft.plugins.getPlugin('recaptchaV3', true) and renderReCaptcha | default and craft.recaptchaV3.hasRecaptchaKeys %}\n    {% set reCaptchaSiteKey = craft.recaptchaV3.getRecaptchaSiteKey %}\n\n    {% if reCaptchaSiteKey %}\n        \u003cscript src=\"https://www.google.com/recaptcha/api.js?render={{ reCaptchaSiteKey }}\"\u003e\u003c/script\u003e\n        \u003cscript\u003e\n            document.addEventListener('DOMContentLoaded', function(event) {\n                var recaptchaResponses = document.querySelectorAll('input[name=\"g-recaptcha-response\"]');\n\n                for (var index = 0; index \u003c recaptchaResponses.length; index++) {\n                    var form = recaptchaResponses[index].closest('form');\n\n                    if (form !== null) {\n                        form.addEventListener('submit', getRecaptchaToken);\n                    }\n                }\n            });\n\n            function getRecaptchaToken(event) {\n                event.preventDefault();\n                var form = event.target;\n\n                if (form !== null) {\n                    var recaptchaResponse = form.querySelector('input[name=\"g-recaptcha-response\"]');\n                    var recaptchaAction = recaptchaResponse.dataset.action !== undefined ? recaptchaResponse.dataset.action : 'submit';\n\n                    if (recaptchaResponse !== null) {\n                        grecaptcha.ready(function() {\n                            grecaptcha.execute('{{ reCaptchaSiteKey }}', { action: recaptchaAction }).then(function(token) {\n                                recaptchaResponse.value = token;\n                                form.submit();\n                            });\n                        });\n                    }\n                }\n            }\n        \u003c/script\u003e\n    {% endif %}\n{% endif %}\n```\n\nIf you use \u003cb\u003eFormerly\u003c/b\u003e, here is code example to use.\u003cbr/\u003e\nIn craft/plugins/recaptchav3/RecaptchaV3Plugin.php\n```\nif (craft()-\u003eplugins-\u003egetPlugin('formerly', true)) {\n    if ($reCaptchaSecretKey = craft()-\u003erecaptchaV3-\u003egetSecretKey()) {\n        craft()-\u003eon('formerly_submissions.onBeforePost', function (Event $event) {\n            $submission = $event-\u003eparams['submission'];\n            $form = craft()-\u003eformerly_forms-\u003egetFormById($submission-\u003eformId);\n\n            if ($form-\u003ehandle == 'contactUs' \u0026\u0026 ! empty(craft()-\u003erecaptchaV3-\u003egetSecretKey())) {\n                if (! craft()-\u003erecaptchaV3-\u003everify(craft()-\u003erequest-\u003egetPost('g-recaptcha-response', null))) {\n                    $error = Craft::t('recaptcha.error.message');\n                    $submission-\u003eaddError('recaptcha', $error);\n                }\n            }\n        });\n    }\n}\n```\n\nand in your template :\n```\nBetween {% extends %} and {% block content %}\n{% set renderReCaptcha = true %}\n\nIn {% block content %} :\n{% if submission is defined and submission.getAllErrors() | length %}\n    \u003cdiv class=\"error\"\u003e\n        {% for error in submission.getAllErrors() %}\n            \u003cli\u003e{{ error }}\u003c/li\u003e\n        {% endfor %}\n    \u003c/div\u003e\n{% endif %}\n```\n\nFor \u003cb\u003ea\u0026m forms\u003c/b\u003e\u003cbr/\u003e\nIn craft/plugins/recaptchav3/RecaptchaV3Plugin.php\n```\nif (craft()-\u003eplugins-\u003egetPlugin('amforms', true)) {\n    if ($reCaptchaSecretKey = craft()-\u003erecaptchaV3-\u003egetSecretKey()) {\n        craft()-\u003eon('amForms_submissions.onBeforeSaveSubmission', function (Event $event) {\n            $submission = $event-\u003eparams['submission'];\n            $form = $submission-\u003egetAttribute('form');\n\n            if (in_array($form-\u003ehandle, ['contact-en', 'contact-fr']) \u0026\u0026 ! empty(craft()-\u003erecaptchaV3-\u003egetSecretKey())) {\n                if (! craft()-\u003erecaptchaV3-\u003everify(craft()-\u003erequest-\u003egetPost('g-recaptcha-response', null))) {\n                    $event-\u003eperformAction = false;\n                    $error = Craft::t('recaptcha.error.message');\n                    $submission-\u003eaddError('recaptcha', $error);\n                }\n            }\n        });\n    }\n}\n```\n\n## In your template\n\nIf you want to render reCAPTCHA only in one (or more) specific template, you can set \na variable between {% extends %} and {% block content %}\n```\n{% set renderReCaptcha = true %}\n```\n\nYou can import macro in  the template directly :\n\n```\n{% macro errorList(errors) %}\n    {% if errors %}\n        \u003cul class=\"errors\"\u003e\n            {% for error in errors %}\n                \u003cli\u003e{{ error }}\u003c/li\u003e\n            {% endfor %}\n        \u003c/ul\u003e\n    {% endif %}\n{% endmacro %}\n{% from _self import errorList %}\n```\n\nor create a file with all your macros and import it, as described below.\n\nCreate a file _macros.twig in templates folder and paste this code :\n```\n{% macro errorList(errors) %}\n    {% if errors %}\n        \u003cul class=\"errors\"\u003e\n            {% for error in errors %}\n                \u003cli\u003e{{ error }}\u003c/li\u003e\n            {% endfor %}\n        \u003c/ul\u003e\n    {% endif %}\n{% endmacro %}\n```\n\nIn your template :\n```\n{% import \"_macros\" as macros %}\n```\n\nIn {% block content %}, copy this code where you want the reCAPTCHA error to be outputted :\n```\n{% if formHandle is defined %}\n    {{ errorList(formHandle.getErrors('recaptcha')) }}\n{% endif %}\n```\n\nor if your macro is in a file and has been imported :\n```\n{% if formHandle is defined %}\n    {{ macros.errorList(formHandle.getErrors('recaptcha')) }}\n{% endif %}\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fglobalia%2Fcraft-recaptcha-v3","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fglobalia%2Fcraft-recaptcha-v3","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fglobalia%2Fcraft-recaptcha-v3/lists"}