diff --git a/CHANGELOG.md b/CHANGELOG.md index 16878729..66745e5b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,18 @@ +# v5.0.0 +## 02/17/2021 + +1. [](#new) + * Requires **Grav 1.7.0** + * Allow admins to temporarily disable form process actions by setting the value to `false` [#481](https://github.com/getgrav/grav-plugin-form/pull/481) +1. [](#improved) + * Add `id` attribute to hidden field [#495](https://github.com/getgrav/grav-plugin-form/pull/495) + * Escape text as YAML in multi-line textarea [#464](https://github.com/getgrav/grav-plugin-form/pull/464) +1. [](#bugfix) + * Fixed reCaptcha v3 incompatibility with multiple forms on the same page sharing different actions [#416](https://github.com/getgrav/grav-plugin-form/issues/416) + * Toggle fields do not save `false` if they are `toggleable` [#497](https://github.com/getgrav/grav-plugin-form/issues/497) + * Data template fixes [#494](https://github.com/getgrav/grav-plugin-form/pull/494) + * Fix deprecated Twig method + # v4.3.1 ## 01/31/2021 diff --git a/README.md b/README.md index d171e9e0..2a624899 100644 --- a/README.md +++ b/README.md @@ -21,7 +21,7 @@ enabled: true # How to use the Form Plugin The Learn site has two pages describing how to use the Form Plugin: -- [Forms](http://learn.getgrav.org/advanced/forms) +- [Forms](https://learn.getgrav.org/forms) - [Add a contact form](http://learn.getgrav.org/forms/forms/example-form) # Using email @@ -30,7 +30,9 @@ Note: when using email functionality in your forms, make sure you have configure # NOTES: -As of version **Form version 4.0.6**, form labels are now being output with the `|raw` filter. If you wish to show HTML in your form label, ie `Root Folder `, then you need to escape that in your form definition: +As of version **Form 5.0.0** Grav 1.7+ is required. + +As of version **Form 4.0.6**, form labels are now being output with the `|raw` filter. If you wish to show HTML in your form label, ie `Root Folder `, then you need to escape that in your form definition: ```yaml label: Root Folder <root> diff --git a/blueprints.yaml b/blueprints.yaml index f85e7cc1..7faa657d 100644 --- a/blueprints.yaml +++ b/blueprints.yaml @@ -1,7 +1,7 @@ name: Form slug: form type: plugin -version: 4.3.1 +version: 5.0.0 testing: false description: Enables the forms handling icon: check-square @@ -15,7 +15,7 @@ bugs: https://github.com/getgrav/grav-plugin-form/issues license: MIT dependencies: - - { name: grav, version: '>=1.6.0' } + - { name: grav, version: '>=1.7.0' } form: validation: strict diff --git a/classes/Form.php b/classes/Form.php index dad2974b..71c1a3bf 100644 --- a/classes/Form.php +++ b/classes/Form.php @@ -915,6 +915,11 @@ public function post() $data = $data[$action]; } + // do not execute action, if deactivated + if (false === $data) { + continue; + } + $event = new Event(['form' => $this, 'action' => $action, 'params' => $data]); $grav->fireEvent('onFormProcessed', $event); diff --git a/composer.json b/composer.json index e0953365..01676515 100644 --- a/composer.json +++ b/composer.json @@ -20,7 +20,7 @@ "docs": "https://github.com/getgrav/grav-plugin-form/blob/master/README.md" }, "require": { - "php": ">=7.1.3", + "php": "^7.3.6 || ^8.0", "ext-json": "*", "google/recaptcha": "^1.2" }, @@ -34,7 +34,7 @@ }, "config": { "platform": { - "php": "7.1.3" + "php": "7.3.6" } } } diff --git a/form.php b/form.php index bae80f94..8a0df42e 100644 --- a/form.php +++ b/form.php @@ -30,6 +30,7 @@ use RocketTheme\Toolbox\File\File; use RocketTheme\Toolbox\Event\Event; use RuntimeException; +use Twig\Extension\CoreExtension; use Twig\TwigFunction; use function count; use function function_exists; @@ -352,7 +353,7 @@ public function onTwigInitialized(): void new TwigFunction('forms', [$this, 'getForm']) ); - $this->grav['twig']->twig()->getExtension('Twig_Extension_Core')->setEscaper('yaml', function ($twig, $string, $charset) { + $this->grav['twig']->twig()->getExtension(CoreExtension::class)->setEscaper('yaml', function ($twig, $string, $charset) { return Yaml::dump($string); } ); @@ -792,10 +793,11 @@ public function getForm($data = null) return $first_form; } - //No form on this route. Try looking up in the current page first - /** @var Forms $forms */ - $forms = $this->grav['forms']; - return $forms->createPageForm($this->grav['page']); + // Try to get page by defined route first or get current if not found + $page = $this->grav['pages']->find($page_route) ?: $this->grav['page']; + + // Try looking up in the defined page + return $this->grav['forms']->createPageForm($page); } // return the form you are looking for if available diff --git a/templates/forms/default/data.html.twig b/templates/forms/default/data.html.twig index 729157f4..9b6c16fe 100644 --- a/templates/forms/default/data.html.twig +++ b/templates/forms/default/data.html.twig @@ -22,9 +22,12 @@ {% set use_keys = field.use is defined and field.use == 'keys' %} {% for key,value in form.value(scope ~ field.name) %} {% set index = (use_keys ? key : value) %} -
  • {{ field.options[index]|e }}
  • +
  • {{ field.options[index]|t|e }}
  • {% endfor %} + {% elseif field.type == 'radio' %} + {% set value = form.value(scope ~ field.name) %} + {{ field.options[value]|t|e }} {% elseif field.type == 'checkbox' %} {{ (form.value(scope ~ field.name) == 1) ? "GRAV.YES"|t|e : "GRAV.NO"|t|e }} {% elseif field.type == 'select' %} diff --git a/templates/forms/default/data.txt.twig b/templates/forms/default/data.txt.twig index 606a0fe0..7758ad55 100644 --- a/templates/forms/default/data.txt.twig +++ b/templates/forms/default/data.txt.twig @@ -9,7 +9,7 @@ {%- if show_field %} {%- set value = form.value(scope ~ (field.name ?? index)) -%} {%- if value -%} - {{- field.label|t|e }}: {{ string(value is iterable ? value|json_encode : value|e) ~ "\r\n" }} + {{- field.label|t|e }}: {{ string(value is iterable ? value|json_encode : value|escape('yaml')) ~ "\r\n" }} {%- endif -%} {%- endif %} {%- endif %} diff --git a/templates/forms/fields/captcha/captcha.html.twig b/templates/forms/fields/captcha/captcha.html.twig index f9a654a9..07ce494a 100644 --- a/templates/forms/fields/captcha/captcha.html.twig +++ b/templates/forms/fields/captcha/captcha.html.twig @@ -15,11 +15,13 @@ {% do assets.addJs('https://www.google.com/recaptcha/api.js?render='~site_key~'&theme=' ~ theme) %} {##} {% elseif config.plugins.form.recaptcha.version == '2-invisible' %}