Skip to content

Commit 2cf9bdd

Browse files
committed
Merge branch 'release/2.7.0'
2 parents 7d34f24 + 64b252e commit 2cf9bdd

File tree

4 files changed

+33
-35
lines changed

4 files changed

+33
-35
lines changed

CHANGELOG.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,10 @@
1+
# v2.7.0
2+
## 05/16/2017
3+
4+
1. [](#bugfix)
5+
* Fix issue with dynamically added forms (Registration, Profile, Comments, etc) not processed [#149](https://github.com/getgrav/grav-plugin-form/issues/149)
6+
* Fixed issue with nested values not being repopulated on form error [#140](https://github.com/getgrav/grav-plugin-form/issues/140)
7+
18
# v2.6.0
29
## 05/04/2017
310

blueprints.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
name: Form
2-
version: 2.6.0
2+
version: 2.7.0
33
description: Enables the forms handling
44
icon: check-square
55
author:

form.php

Lines changed: 24 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ public function onPageProcessed(Event $e)
125125
public function onPagesInitialized()
126126
{
127127
$submitted = false;
128-
128+
$this->json_response = [];
129129
$cache_id = $this->grav['pages']->getPagesCacheId() . '-form-plugin';
130130

131131
// Get and set the cache of forms if it exists
@@ -141,35 +141,21 @@ public function onPagesInitialized()
141141
$this->flat_forms = $flat_forms;
142142
}
143143

144-
// Enable form events if there's a POST
145-
if (!empty($_POST)) {
146-
$this->enable([
147-
'onFormProcessed' => ['onFormProcessed', 0],
148-
'onFormValidationError' => ['onFormValidationError', 0]
149-
]);
150-
}
151-
152-
if ($this->isAdmin() && !empty($_POST)) {
144+
// No forms in pages, try the current one in the page
145+
if (empty($this->forms)) {
153146

154147
$page = $this->grav['page'];
155148
if (!$page) {
156149
return;
157150
}
158151

152+
// Create form from page
159153
$header = $page->header();
160-
161154
if (isset($header->form) && is_array($header->form)) {
162-
// Create form
163155
$this->form = new Form($page);
164-
$this->form->post();
165156
}
166157

167-
} elseif ($this->forms) {
168-
169-
$this->enable([
170-
'onFormFieldTypes' => ['onFormFieldTypes', 0],
171-
]);
172-
158+
} else {
173159
// Regenerate list of flat_forms if not already populated
174160
if (empty($this->flat_forms)) {
175161
$this->flat_forms = Utils::arrayFlatten($this->forms);
@@ -179,28 +165,33 @@ public function onPagesInitialized()
179165
if ($this->recache_forms) {
180166
$this->grav['cache']->save($cache_id, [$this->forms, $this->flat_forms]);
181167
}
168+
}
182169

183-
// Handle posting if needed.
184-
if (!empty($_POST) && (isset($_POST['data']) || isset($_POST['__form-file-uploader__']))) {
170+
// Enable form events if there's a POST
171+
if (isset($_POST) && isset($_POST['form-nonce'])) {
172+
$this->enable([
173+
'onFormProcessed' => ['onFormProcessed', 0],
174+
'onFormValidationError' => ['onFormValidationError', 0],
175+
'onFormFieldTypes' => ['onFormFieldTypes', 0],
176+
]);
185177

178+
// Retrieve the form if it's not already set
179+
if (!isset($this->form)) {
186180
$current_form_name = $this->getFormName($this->grav['page']);
187-
$this->json_response = [];
188181
$this->form = $this->getFormByName($current_form_name);
182+
}
189183

190-
if (!$this->form && isset($this->grav['page']->header()->form)) {
191-
$this->form = new Form($this->grav['page']);
192-
}
193-
194-
if ($this->form) {
195-
if ($this->grav['uri']->extension() === 'json' && isset($_POST['__form-file-uploader__'])) {
196-
$this->json_response = $this->form->uploadFiles();
197-
} else {
198-
$this->form->post();
199-
$submitted = true;
200-
}
184+
// Post the form
185+
if ($this->form) {
186+
if ($this->grav['uri']->extension() === 'json' && isset($_POST['__form-file-uploader__'])) {
187+
$this->json_response = $this->form->uploadFiles();
188+
} else {
189+
$this->form->post();
190+
$submitted = true;
201191
}
202192
}
203193

194+
204195
// Clear flash objects for previously uploaded files
205196
// whenever the user switches page / reloads
206197
// ignoring any JSON / extension call

templates/forms/fields/fieldset/fieldset.html.twig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
{% if field.fields %}
77
{% for field in field.fields %}
88
{% if field.type %}
9-
{% set value = data.value(field.name) %}
9+
{% set value = form.value(field.name) %}
1010
{% include ["forms/fields/#{field.type}/#{field.type}.html.twig", 'forms/fields/text/text.html.twig'] %}
1111
{% endif %}
1212
{% endfor %}

0 commit comments

Comments
 (0)