diff --git a/CHANGELOG.md b/CHANGELOG.md index 7a3b5c3e..ba872f74 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,7 +1,10 @@ -# v2.2.1 -## 03/xx/2017 +# v2.3.0 +## 03/17/2017 -![](#bugfix) +1. [](#new) + * Ability to process any form on any page via `action:`. Super useful if you want to handle form processing on some other non-form page (or Ajax) + * Added the ability for the form to set the `template:` to use to render the form processing response. +1. [](#bugfix) * Fix `number` field so it works with min value `0` [#130](https://github.com/getgrav/grav-plugin-form/issues/130) # v2.2.0 @@ -11,7 +14,7 @@ * Added new `fieldset` form field [#125](https://github.com/getgrav/grav-plugin-form/issues/125) * Added new `conditional form field` to show fields only if some `condition` is set 1. [](#improved) - * Added the option to have outerclasses on buttons [#124](https://github.com/getgrav/grav-plugin-form/issues/124) + * Added the option to have outer-classes on buttons [#124](https://github.com/getgrav/grav-plugin-form/issues/124) * Added the option to disable fields label if not defined [#126](https://github.com/getgrav/grav-plugin-form/issues/126) # v2.1.1 diff --git a/blueprints.yaml b/blueprints.yaml index 192aef1a..72cb4741 100644 --- a/blueprints.yaml +++ b/blueprints.yaml @@ -1,5 +1,5 @@ name: Form -version: 2.2.0 +version: 2.3.0 description: Enables the forms handling icon: check-square author: diff --git a/form.php b/form.php index d46e0466..103b92b9 100644 --- a/form.php +++ b/form.php @@ -189,16 +189,16 @@ public function onPagesInitialized() $current_form_name = $this->getFormName($this->grav['page']); $this->json_response = []; - if ($form = $this->getFormByName($current_form_name)) { + if ($this->form = $this->getFormByName($current_form_name)) { if ($this->grav['uri']->extension() === 'json' && isset($_POST['__form-file-uploader__'])) { - $this->json_response = $form->uploadFiles(); + $this->json_response = $this->form->uploadFiles(); } else { - $form->post(); + $this->form->post(); $submitted = true; } } elseif (isset($this->grav['page']->header()->form)) { - $form = new Form($this->grav['page']); - $form->post(); + $this->form = new Form($this->grav['page']); + $this->form->post(); $submitted = true; } } @@ -259,7 +259,9 @@ public function onTwigVariables(Event $event = null) $current_page_route = $this->getCurrentPageRoute(); $found_forms = []; - if (!isset($this->grav['twig']->twig_vars['form'])) { + if (isset($this->form)) { + $this->grav['twig']->twig_vars['form'] = $this->form; + } elseif (!isset($this->grav['twig']->twig_vars['form'])) { if (isset($this->forms[$page_route])) { $found_forms = $this->forms[$page_route]; } elseif (isset($this->forms[$current_page_route])) { @@ -527,6 +529,11 @@ protected function process($form) } } } + + // Set page template if passed by form + if (isset($form->template)) { + $this->grav['page']->template($form->template); + } } /** diff --git a/templates/form-messages.html.twig b/templates/form-messages.html.twig new file mode 100644 index 00000000..bf731229 --- /dev/null +++ b/templates/form-messages.html.twig @@ -0,0 +1,7 @@ +{% if form.message %} + {% if form.inline_errors and form.messages %} +
+ {% else %} + + {% endif %} +{% endif %} diff --git a/templates/forms/fields/captcha/captcha.html.twig b/templates/forms/fields/captcha/captcha.html.twig index e0dabc85..f008179e 100644 --- a/templates/forms/fields/captcha/captcha.html.twig +++ b/templates/forms/fields/captcha/captcha.html.twig @@ -4,7 +4,7 @@