diff --git a/CHANGELOG.md b/CHANGELOG.md index 2141aed7..d4ad9a43 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,11 @@ +# v5.0.2 +## 04/23/2021 + +1. [](#improved) + * Better message for invalid nonce [#513](https://github.com/getgrav/grav-plugin-form/issues/513) + * Better error if `Form::getPage()` gets called too early [#518](https://github.com/getgrav/grav-plugin-form/issues/518) + * Added support for custom Toggle id + # v5.0.1 ## 03/17/2021 diff --git a/blueprints.yaml b/blueprints.yaml index 66b8ab07..be5b4ad5 100644 --- a/blueprints.yaml +++ b/blueprints.yaml @@ -1,7 +1,7 @@ name: Form slug: form type: plugin -version: 5.0.1 +version: 5.0.2 description: Enables the forms handling icon: check-square author: diff --git a/classes/Form.php b/classes/Form.php index 71c1a3bf..6bfcdd67 100644 --- a/classes/Form.php +++ b/classes/Form.php @@ -12,6 +12,7 @@ use Grav\Common\Inflector; use Grav\Common\Language\Language; use Grav\Common\Page\Interfaces\PageInterface; +use Grav\Common\Page\Pages; use Grav\Common\Security; use Grav\Common\Uri; use Grav\Common\Utils; @@ -390,11 +391,21 @@ public function getFields(): array /** * Return page object for the form. * + * Can be called only after onPageInitialize event has fired. + * * @return PageInterface + * @throws \LogicException */ public function getPage(): PageInterface { - return Grav::instance()['pages']->dispatch($this->page); + /** @var Pages $pages */ + $pages = Grav::instance()['pages']; + $page = $pages->find($this->page); + if (null === $page) { + throw new \LogicException('Form::getPage() method was called too early!'); + } + + return $page; } /** diff --git a/languages.yaml b/languages.yaml index a6bd8bdf..4b2f06d5 100644 --- a/languages.yaml +++ b/languages.yaml @@ -1,7 +1,7 @@ en: PLUGIN_FORM: NOT_VALIDATED: "Form not validated. One or more required fields are missing." - NONCE_NOT_VALIDATED: "Oops there was a problem, please check your input and submit the form again." + NONCE_NOT_VALIDATED: "Oops, your form has timed out, please reload the page and submit the form again." FILES: "Files Upload" FORM_ALREADY_SUBMITTED: "This form has already been submitted." ALLOW_MULTIPLE: "Allow More than one file" diff --git a/templates/forms/fields/toggle/toggle.html.twig b/templates/forms/fields/toggle/toggle.html.twig index e1353e9b..1c51b2e0 100644 --- a/templates/forms/fields/toggle/toggle.html.twig +++ b/templates/forms/fields/toggle/toggle.html.twig @@ -33,7 +33,7 @@ {% for key, text in field.options %} {% set key = key|string %} - {% set id = "toggle_" ~ field.name ~ key %} + {% set id = (field.id ?? ("toggle_" ~ field.name)) ~ key %} {% set translation = text|t|trim %}