Skip to content

Commit

Permalink
Merge branch 'release/3.0.2'
Browse files Browse the repository at this point in the history
  • Loading branch information
rhukster committed Apr 22, 2019
2 parents 756db6b + fce7d38 commit d9cf0a1
Show file tree
Hide file tree
Showing 8 changed files with 55 additions and 10 deletions.
12 changes: 12 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,18 @@
# v3.0.2
## 04/22/2019

1. [](#new)
* Support for Google Recaptcha theme (light/dark) doesn't work in v3 yet.
1. [](#improved)
* Visual upgrade for form field descriptions [#335](https://github.com/getgrav/grav-plugin-form/pull/335)
1. [](#bugfix)
* Fixed issue with `recaptcha_not_validated` property not being used

# v3.0.1
## 04/15/2019

1. [](#new)
* Added support for form task in blueprint
1. [](#bugfix)
* Fix url field output in list view

Expand Down
10 changes: 9 additions & 1 deletion blueprints.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: Form
version: 3.0.1
version: 3.0.2
testing: false
description: Enables the forms handling
icon: check-square
Expand Down Expand Up @@ -177,6 +177,14 @@ form:
2-checkbox: v2 - Checkbox
2-invisible: v2 - Invisible
3: v3 - Latest
recaptcha.theme:
type: select
label: Theme
default: light
options:
light: Light Theme
dark: Dark Theme
recaptcha.site_key:
recaptcha.site_key:
type: text
label: PLUGIN_FORM.RECAPTCHA_SITE_KEY
Expand Down
14 changes: 13 additions & 1 deletion form.php
Original file line number Diff line number Diff line change
Expand Up @@ -380,9 +380,21 @@ public function onFormProcessed(Event $event)

if (!$resp->isSuccess()) {
$errors = $resp->getErrorCodes();
$message = $this->grav['language']->translate('PLUGIN_FORM.ERROR_VALIDATING_CAPTCHA');

$fields = $form->value()->blueprints()->get('form/fields');
foreach ($fields as $field) {
$type = $field['type'] ?? 'text';
$field_message = $field['recaptcha_not_validated'] ?? null;
if ($type == 'captcha' && $field_message) {
$message = $field_message;
break;
}
}

$this->grav->fireEvent('onFormValidationError', new Event([
'form' => $form,
'message' => $this->grav['language']->translate('PLUGIN_FORM.ERROR_VALIDATING_CAPTCHA')
'message' => $message
]));

$this->grav['log']->addWarning('Form reCAPTCHA Errors: [' . $uri->route() . '] ' . json_encode($errors));
Expand Down
7 changes: 4 additions & 3 deletions form.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ files:
accept: # List of mime/types or file extensions allowed (ie, image/*,.zip,.mp4)
- image/*
recaptcha:
version: 2-checkbox
site_key:
secret_key:
version: 2-checkbox
theme: light
site_key:
secret_key:
2 changes: 1 addition & 1 deletion templates/forms/default/field.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@
{% endblock %}
{% endblock %}
{% if field.description %}
<div class="form-extra-wrapper {{ field.size|e }} {{ field.wrapper_classes }}">
<div class="form-extra-wrapper {{ field.wrapper_classes }}">
<span class="form-description">
{% if field.markdown %}
{{ field.description|t|markdown(false)|raw }}
Expand Down
2 changes: 2 additions & 0 deletions templates/forms/default/form.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@
{% endblock %}

{% include "forms/fields/formname/formname.html.twig" %}
{% include "forms/fields/formtask/formtask.html.twig" %}

{% block inner_markup_fields_end %}{% endblock %}

Expand Down Expand Up @@ -121,6 +122,7 @@
{% endblock %}

{% include 'forms/fields/uniqueid/uniqueid.html.twig' %}

{{ nonce_field(form.getNonceAction() ?? 'form', form.getNonceName() ?? 'form-nonce')|raw }}
</form>

Expand Down
10 changes: 6 additions & 4 deletions templates/forms/fields/captcha/captcha.html.twig
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
{% extends "forms/field.html.twig" %}

{% set config = grav.config %}
{% set site_key = field.recaptcha_site_key ?: config.plugins.form.recaptcha.site_key %}
{% set action = (page.route|trim('/') ~ '-' ~ form.name)|underscorize %}
{% set formName = form.name|underscorize %}
{% set theme = config.plugins.form.recaptcha.theme ?? 'light' %}

{% block label %}{% endblock %}

{% block input %}
{% if config.plugins.form.recaptcha.version == 3 %}
{% if config.plugins.form.recaptcha.version is same as(3) %}
{#{% do assets.addJs('https://www.google.com/recaptcha/api.js?render='~site_key) %}#}
<script src='https://www.google.com/recaptcha/api.js?render={{ site_key }}'></script>
<script src='https://www.google.com/recaptcha/api.js?render={{ site_key }}&theme={{ theme }}'></script>
<script>
jQuery('form').each(function(index, form) {
form = jQuery(form);
Expand Down Expand Up @@ -47,7 +49,7 @@
}
</script>

<script src="https://www.google.com/recaptcha/api.js?onload=captchaOnloadCallback_{{ formName }}&hl={{ grav.language.language }}"
<script src="https://www.google.com/recaptcha/api.js?onload=captchaOnloadCallback_{{ formName }}&hl={{ grav.language.language }}&theme={{ theme }}"
async defer></script>
{% else %}
<script>
Expand All @@ -64,7 +66,7 @@
grecaptcha.reset();
};
</script>
<script src="https://www.google.com/recaptcha/api.js?onload=captchaOnloadCallback_{{ formName }}&render=explicit&hl={{ grav.language.language }}"
<script src="https://www.google.com/recaptcha/api.js?onload=captchaOnloadCallback_{{ formName }}&render=explicit&hl={{ grav.language.language }}&theme={{ theme }} "
async defer></script>
<div class="g-recaptcha" id="g-recaptcha-{{ formName }}"></div>
{% endif %}
Expand Down
8 changes: 8 additions & 0 deletions templates/forms/fields/formtask/formtask.html.twig
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{% extends "forms/field.html.twig" %}

{% block field %}
{% if form.task %}
<input type="hidden" name="task" value="{{ form.task }}" />
{% endif %}
{% endblock %}

0 comments on commit d9cf0a1

Please sign in to comment.