Skip to content

Commit

Permalink
Merge branch 'release/2.7.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
rhukster committed May 16, 2017
2 parents 7d34f24 + 64b252e commit 2cf9bdd
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 35 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
# v2.7.0
## 05/16/2017

1. [](#bugfix)
* Fix issue with dynamically added forms (Registration, Profile, Comments, etc) not processed [#149](https://github.com/getgrav/grav-plugin-form/issues/149)
* Fixed issue with nested values not being repopulated on form error [#140](https://github.com/getgrav/grav-plugin-form/issues/140)

# v2.6.0
## 05/04/2017

Expand Down
2 changes: 1 addition & 1 deletion blueprints.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: Form
version: 2.6.0
version: 2.7.0
description: Enables the forms handling
icon: check-square
author:
Expand Down
57 changes: 24 additions & 33 deletions form.php
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ public function onPageProcessed(Event $e)
public function onPagesInitialized()
{
$submitted = false;

$this->json_response = [];
$cache_id = $this->grav['pages']->getPagesCacheId() . '-form-plugin';

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

// Enable form events if there's a POST
if (!empty($_POST)) {
$this->enable([
'onFormProcessed' => ['onFormProcessed', 0],
'onFormValidationError' => ['onFormValidationError', 0]
]);
}

if ($this->isAdmin() && !empty($_POST)) {
// No forms in pages, try the current one in the page
if (empty($this->forms)) {

$page = $this->grav['page'];
if (!$page) {
return;
}

// Create form from page
$header = $page->header();

if (isset($header->form) && is_array($header->form)) {
// Create form
$this->form = new Form($page);
$this->form->post();
}

} elseif ($this->forms) {

$this->enable([
'onFormFieldTypes' => ['onFormFieldTypes', 0],
]);

} else {
// Regenerate list of flat_forms if not already populated
if (empty($this->flat_forms)) {
$this->flat_forms = Utils::arrayFlatten($this->forms);
Expand All @@ -179,28 +165,33 @@ public function onPagesInitialized()
if ($this->recache_forms) {
$this->grav['cache']->save($cache_id, [$this->forms, $this->flat_forms]);
}
}

// Handle posting if needed.
if (!empty($_POST) && (isset($_POST['data']) || isset($_POST['__form-file-uploader__']))) {
// Enable form events if there's a POST
if (isset($_POST) && isset($_POST['form-nonce'])) {
$this->enable([
'onFormProcessed' => ['onFormProcessed', 0],
'onFormValidationError' => ['onFormValidationError', 0],
'onFormFieldTypes' => ['onFormFieldTypes', 0],
]);

// Retrieve the form if it's not already set
if (!isset($this->form)) {
$current_form_name = $this->getFormName($this->grav['page']);
$this->json_response = [];
$this->form = $this->getFormByName($current_form_name);
}

if (!$this->form && isset($this->grav['page']->header()->form)) {
$this->form = new Form($this->grav['page']);
}

if ($this->form) {
if ($this->grav['uri']->extension() === 'json' && isset($_POST['__form-file-uploader__'])) {
$this->json_response = $this->form->uploadFiles();
} else {
$this->form->post();
$submitted = true;
}
// Post the form
if ($this->form) {
if ($this->grav['uri']->extension() === 'json' && isset($_POST['__form-file-uploader__'])) {
$this->json_response = $this->form->uploadFiles();
} else {
$this->form->post();
$submitted = true;
}
}


// Clear flash objects for previously uploaded files
// whenever the user switches page / reloads
// ignoring any JSON / extension call
Expand Down
2 changes: 1 addition & 1 deletion templates/forms/fields/fieldset/fieldset.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
{% if field.fields %}
{% for field in field.fields %}
{% if field.type %}
{% set value = data.value(field.name) %}
{% set value = form.value(field.name) %}
{% include ["forms/fields/#{field.type}/#{field.type}.html.twig", 'forms/fields/text/text.html.twig'] %}
{% endif %}
{% endfor %}
Expand Down

0 comments on commit 2cf9bdd

Please sign in to comment.