Skip to content

Commit

Permalink
Merge branch 'release/2.15.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
rhukster committed May 31, 2018
2 parents 12f3f39 + f2df03c commit a76ccc9
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 11 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
# v2.15.0
## 05/31/2018

1. [](#new)
* Added support for `Uri::post()`
* Added support for `autocapitalize`, `inputmode`, and `spellcheck` options in field definitions

# v2.14.1
## 05/15/2018

Expand Down
4 changes: 2 additions & 2 deletions blueprints.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: Form
version: 2.14.1
version: 2.15.0
description: Enables the forms handling
icon: check-square
author:
Expand All @@ -12,7 +12,7 @@ bugs: https://github.com/getgrav/grav-plugin-form/issues
license: MIT

dependencies:
- { name: grav, version: '>=1.3.9' }
- { name: grav, version: '>=1.4.5' }

form:
validation: strict
Expand Down
11 changes: 7 additions & 4 deletions classes/Form.php
Original file line number Diff line number Diff line change
Expand Up @@ -625,11 +625,14 @@ public function filesSessionRemove()
public function post()
{
$grav = Grav::instance();
$uri = $grav['uri']->url;
$uri = $grav['uri'];
$url = $uri->url;
$session = $grav['session'];

if (isset($_POST)) {
$this->values = new Data(isset($_POST) ? (array)$_POST : []);
$post = $uri->post();

if ($post) {
$this->values = new Data((array)$post);
$data = $this->values->get('data');

// Add post data to form dataset
Expand Down Expand Up @@ -694,7 +697,7 @@ public function post()
// Process previously uploaded files for the current URI
// and finally store them. Everything else will get discarded
$queue = $session->getFlashObject('files-upload');
$queue = $queue[base64_encode($uri)];
$queue = $queue[base64_encode($url)];
if (is_array($queue)) {
foreach ($queue as $key => $files) {
foreach ($files as $destination => $file) {
Expand Down
15 changes: 10 additions & 5 deletions form.php
Original file line number Diff line number Diff line change
Expand Up @@ -183,9 +183,11 @@ public function onPageInitialized()
'onFormFieldTypes' => ['onFormFieldTypes', 0],
]);

$uri = $this->grav['uri'];

// Post the form
if ($this->form) {
if (isset($_POST['__form-file-uploader__']) && $this->grav['uri']->extension() === 'json') {
if ($uri->post('__form-file-uploader__') && $uri->extension() === 'json') {
$this->json_response = $this->form->uploadFiles();
} else if ($this->form && isset($_POST['__form-file-remover__']) && $this->grav['uri']->extension() === 'json') {
$this->json_response = $this->form->filesSessionRemove();
Expand All @@ -198,7 +200,7 @@ public function onPageInitialized()
// Clear flash objects for previously uploaded files
// whenever the user switches page / reloads
// ignoring any JSON / extension call
if (!$submitted && null === $this->grav['uri']->extension()) {
if (!$submitted && null === $uri->extension()) {
// Discard any previously uploaded files session.
// and if there were any uploaded file, remove them from the filesystem
if ($flash = $this->grav['session']->getFlashObject('files-upload')) {
Expand Down Expand Up @@ -711,7 +713,9 @@ protected function getFormByName($form_name)
*/
protected function shouldProcessForm()
{
$status = isset($_POST['form-nonce']) ? true : false; // php72 quirk?
$uri = $this->grav['uri'];
$nonce = $uri->post('form-nonce');
$status = $nonce ? true : false; // php72 quirk?
$refresh_prevention = null;

if ($status && $this->form()) {
Expand All @@ -726,7 +730,7 @@ protected function shouldProcessForm()
$refresh_prevention = $this->config->get('plugins.form.refresh_prevention', false);
}

$unique_form_id = filter_input(INPUT_POST, '__unique_form_id__', FILTER_SANITIZE_STRING);
$unique_form_id = $uri->post('__unique_form_id__', FILTER_SANITIZE_STRING);

if ($refresh_prevention && $unique_form_id) {
if ($this->grav['session']->unique_form_id !== $unique_form_id) {
Expand Down Expand Up @@ -769,7 +773,8 @@ protected function form($page = null)
$page = $this->grav['page'];
}

$form_name = filter_input(INPUT_POST, '__form-name__');
$form_name = $this->grav['uri']->post('__form-name__', FILTER_SANITIZE_STRING);

if (!$form_name) {
$form_name = $page ? $page->slug() : null;
}
Expand Down
4 changes: 4 additions & 0 deletions templates/forms/default/field.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,10 @@
{% if field.novalidate in ['on', 'true', 1] %}novalidate="novalidate"{% endif %}
{% if field.readonly in ['on', 'true', 1] %}readonly="readonly"{% endif %}
{% if field.autocomplete in ['on', 'off', 'new-password'] %}autocomplete="{{ field.autocomplete }}"{% endif %}
{% if field.autocapitalize in ['off', 'characters', 'words', 'sentences'] %}autocapitalize="{{ field.autocapitalize }}"{% endif %}
{% if field.inputmode in ['none', 'text', 'decimal', 'numeric', 'tel', 'search', 'emaiil', 'url'] %}inputmode="{{ field.inputmode }}"{% endif %}
{% if field.spellcheck in ['true', 'false'] %}spellcheck="{{ field.spellcheck }}"{% endif %}

{% if field.attributes is defined %}
{% for attribute in field.attributes %}
{{ attribute.name }}="{{ attribute.value|e }}"
Expand Down

0 comments on commit a76ccc9

Please sign in to comment.