Skip to content

Commit 71ec621

Browse files
committed
Manual merge of PR getgrav#34 - form config options for Captcha keys
1 parent 4a78a0c commit 71ec621

File tree

5 files changed

+39
-4
lines changed

5 files changed

+39
-4
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
1. [](#new)
55
* Added support for advanced blueprint functionality in forms
6+
* Added site-wide form options to set Google Captcha site + secret keys [#34](https://github.com/getgrav/grav-plugin-form/pull/34)
67
* Session-based 'flash' storage of form for redirects [#48](https://github.com/getgrav/grav-plugin-form/issues/48)
78
* Added ability to **append** to file if you include a `process: save: body:` template attribute [#65](https://github.com/getgrav/grav-plugin-form/issues/65)
89
1. [](#improved)

blueprints.yaml

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,3 +59,19 @@ form:
5959
- image/*
6060
validate:
6161
type: commalist
62+
63+
recaptcha:
64+
type: section
65+
title: PLUGIN_FORM.RECAPTCHA
66+
67+
fields:
68+
recaptcha.site_key:
69+
type: text
70+
label: PLUGIN_FORM.RECAPTCHA_SITE_KEY
71+
help: PLUGIN_FORM.RECAPTCHA_SITE_KEY_HELP
72+
default: ''
73+
recaptcha.secret_key:
74+
type: text
75+
label: PLUGIN_FORM.RECAPTCHA_SECRET_KEY
76+
help: PLUGIN_FORM.RECAPTCHA_SECRET_KEY_HELP
77+
default: ''

form.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ public function onFormProcessed(Event $event)
117117
case 'captcha':
118118
// Validate the captcha
119119
$query = http_build_query([
120-
'secret' => isset($params['recaptcha_secret']) ? $params['recaptcha_secret'] : $params['recatpcha_secret'], //Allow value with typo for BC
120+
'secret' => isset($params['recaptcha_secret']) ? $params['recaptcha_secret'] : isset($params['recatpcha_secret']) ? $params['recatpcha_secret'] : $this->config->get('plugins.form.recaptcha.secret_key'),
121121
'response' => $this->form->value('g-recaptcha-response', true)
122122
]);
123123
$url = 'https://www.google.com/recaptcha/api/siteverify?' . $query;

languages.yaml

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,11 @@ en:
1212
ERROR_VALIDATING_CAPTCHA: "Error validating the Captcha"
1313
DATA_SUMAMRY: "Here is the summary of what you wrote to us:"
1414
NO_FORM_DATA: "No form data available"
15+
RECAPTCHA: "ReCaptcha"
16+
RECAPTCHA_SITE_KEY: "Site key"
17+
RECAPTCHA_SITE_KEY_HELP: "For more info visit https://developers.google.com/recaptcha"
18+
RECAPTCHA_SECRET_KEY: "Secret key"
19+
RECAPTCHA_SECRET_KEY_HELP: "For more info visit https://developers.google.com/recaptcha"
1520

1621
de:
1722
PLUGIN_FORM:
@@ -28,8 +33,21 @@ de:
2833

2934
es:
3035
PLUGIN_FORM:
31-
NOT_VALIDATED: "Falló la validación del formulario. Uno o más campos obligatorios no fueron capturados."
32-
NONCE_NOT_VALIDATED: "Oops, hay un problema, por favor revice la información capturada e intente enviar el formulario otra vez."
36+
NOT_VALIDATED: "Falló la validación del formulario. Uno o más campos obligatorios no fueron cubiertos."
37+
NONCE_NOT_VALIDATED: "Oops, hay un problema, por favor revise la información e intente enviar el formulario otra vez."
38+
FILES: "Subida de Ficheros"
39+
ALLOW_MULTIPLE: "Permitir más de un fichero"
40+
ALLOW_MULTIPLE_HELP: "Permitir seleccionar más de un fichero para subir."
41+
DESTINATION: "Destino"
42+
DESTINATION_HELP: "El lugar de destino al que subir los ficheros"
43+
ACCEPT: "MIME Types permitidos"
44+
ACCEPT_HELP: "Una lista de MIME Types que se permiten subir."
45+
ERROR_VALIDATING_CAPTCHA: "Error al comrobar el Captcha"
46+
RECAPTCHA: "ReCaptcha"
47+
RECAPTCHA_SITE_KEY: "Site key"
48+
RECAPTCHA_SITE_KEY_HELP: "Para más información visita https://developers.google.com/recaptcha"
49+
RECAPTCHA_SECRET_KEY: "Secret key"
50+
RECAPTCHA_SECRET_KEY_HELP: "Para más información visita https://developers.google.com/recaptcha"
3351

3452
fr:
3553
PLUGIN_FORM:

templates/forms/fields/captcha/captcha.html.twig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
<script>
55
var captchaOnloadCallback = function captchaOnloadCallback() {
66
grecaptcha.render('g-recaptcha', {
7-
'sitekey': "{{field.recaptcha_site_key ?: field.recatpcha_site_key}}",
7+
'sitekey': "{{field.recaptcha_site_key ?: field.recatpcha_site_key ?: config.plugins.form.recaptcha.site_key }}",
88
'callback': captchaValidatedCallback,
99
'expired-callback': captchaExpiredCallback
1010
});

0 commit comments

Comments
 (0)