From 9a577bafe92cf2f58165f17a555ff2461a01c522 Mon Sep 17 00:00:00 2001 From: Djamil Legato Date: Thu, 7 Aug 2014 15:50:33 -0700 Subject: [PATCH 01/11] Added hebe conf --- hebe.json | 15 +++++++++++++++ 1 file changed, 15 insertions(+) create mode 100644 hebe.json diff --git a/hebe.json b/hebe.json new file mode 100644 index 00000000..861d235b --- /dev/null +++ b/hebe.json @@ -0,0 +1,15 @@ +{ + "project":"grav-plugin-form", + "platforms":{ + "grav":{ + "nodes":{ + "plugin":[ + { + "source":"/", + "destination":"/user/plugins/form" + } + ] + } + } + } +} From d305589df581523a81f3dcaef5a748118a44c158 Mon Sep 17 00:00:00 2001 From: Andy Miller Date: Tue, 12 Aug 2014 09:30:05 -0600 Subject: [PATCH 02/11] Refactored some Twig event names for consistency --- form.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/form.php b/form.php index c587eccd..76be85f0 100644 --- a/form.php +++ b/form.php @@ -70,7 +70,7 @@ public function onAfterTwigTemplatesPaths() /** * Make form accessible from twig. */ - public function onAfterSiteTwigVars() + public function onAfterTwigSiteVars() { if (!$this->active) { return; From 8e5f747695c044d831344686ab7a0030684e0897 Mon Sep 17 00:00:00 2001 From: Andy Miller Date: Tue, 19 Aug 2014 19:00:31 -0600 Subject: [PATCH 03/11] Refactoring per the new page events system --- classes/form.php | 8 ++++---- form.php | 41 ++++++++++++++++++++--------------------- 2 files changed, 24 insertions(+), 25 deletions(-) diff --git a/classes/form.php b/classes/form.php index 35bdf0eb..28a12904 100644 --- a/classes/form.php +++ b/classes/form.php @@ -3,11 +3,13 @@ use \Grav\Common\Iterator; use \Grav\Common\Grav; -use \Grav\Common\Registry; +use \Grav\Common\GravTrait; use \Grav\Common\Page\Page; class Form extends Iterator { + use GravTrait; + /** * @var array */ @@ -81,14 +83,12 @@ public function post() $process = isset($this->items['process']) ? $this->items['process'] : array(); if (is_array($process)) { - /** @var Grav $grav */ - $grav = Registry::instance()->get('Grav'); foreach ($process as $action => $data) { if (is_numeric($action)) { $action = \key($data); $data = $data[$action]; } - $grav->fireEvent('onProcessForm', $this, $action, $data); + self::$grav->fireEvent('onFormProcessed', $this, $action, $data); } } else { // Default action. diff --git a/form.php b/form.php index 76be85f0..e5a26e61 100644 --- a/form.php +++ b/form.php @@ -2,7 +2,6 @@ namespace Grav\Plugin; use \Grav\Common\Plugin; -use \Grav\Common\Registry; use \Grav\Common\Page\Page; use \Grav\Common\Page\Pages; use \Grav\Common\Grav; @@ -13,6 +12,7 @@ class FormPlugin extends Plugin { + /** * @var bool */ @@ -24,17 +24,22 @@ class FormPlugin extends Plugin protected $form; /** - * @var Grav + * @return array */ - protected $grav; + public static function getSubscribedEvents() { + return [ + 'onPageInitialized' => ['onPageInitialized', 0], + 'onTwigTemplatePaths' => ['onTwigTemplatePaths', 0], + 'onTwigSiteVariables' => ['onTwigSiteVariables', 0], + 'onFormProcessed' => ['onFormProcessed', 0] + ]; + } /** * Initialize form if the page has one. Also catches form processing if user posts the form. */ - public function onAfterGetPage() + public function onPageInitialized() { - $this->grav = Registry::get('Grav'); - /** @var Page $page */ $page = $this->grav->page; if (!$page) { @@ -54,34 +59,28 @@ public function onAfterGetPage() $this->form->post(); } - $registry = Registry::instance(); - $registry->store('Form', $this->form); + $grav['form'] = $this->form; } } /** * Add current directory to twig lookup paths. */ - public function onAfterTwigTemplatesPaths() + public function onTwigTemplatePaths() { - Registry::get('Twig')->twig_paths[] = __DIR__ . '/templates'; + $this->grav['twig']->twig_paths[] = __DIR__ . '/templates'; } /** * Make form accessible from twig. */ - public function onAfterTwigSiteVars() + public function onTwigSiteVariables() { if (!$this->active) { return; } - /** @var Twig $twig */ - $twig = Registry::get('Twig'); - /** @var Form $form */ - $form = Registry::get('Form'); - - $twig->twig_vars['form'] = $form; + $this->grav['twig']->twig_vars['form'] = $this->grav['form']; } /** @@ -91,7 +90,7 @@ public function onAfterTwigSiteVars() * @param string $task * @param string $params */ - public function onProcessForm(Form $form, $task, $params) + public function onFormProcessed(Form $form, $task, $params) { if (!$this->active) { return; @@ -113,11 +112,11 @@ public function onProcessForm(Form $form, $task, $params) $route = (string) $params; if (!$route || $route[0] != '/') { /** @var Uri $uri */ - $uri = Registry::get('Uri'); + $uri = $this->grav['uri']; $route = $uri->route() . ($route ? '/' . $route : ''); } /** @var Pages $pages */ - $pages = Registry::get('Pages'); + $pages = $this->grav['pages']; $this->grav->page = $pages->dispatch($route, true); break; case 'save': @@ -127,7 +126,7 @@ public function onProcessForm(Form $form, $task, $params) $filename = $prefix . $this->udate($format) . $ext; /** @var Twig $twig */ - $twig = Registry::get('Twig'); + $twig = $this->grav['twig']; $vars = array( 'form' => $this->form ); From 10a3519f25d055e94b16de2286f154c5219b4de1 Mon Sep 17 00:00:00 2001 From: Andy Miller Date: Tue, 19 Aug 2014 21:45:52 -0600 Subject: [PATCH 04/11] trying to get form to work.. not quite working.. not sure why --- form.php | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/form.php b/form.php index e5a26e61..17f2700a 100644 --- a/form.php +++ b/form.php @@ -41,7 +41,7 @@ public static function getSubscribedEvents() { public function onPageInitialized() { /** @var Page $page */ - $page = $this->grav->page; + $page = $this->grav['page']; if (!$page) { return; } @@ -58,8 +58,6 @@ public function onPageInitialized() if (!empty($_POST)) { $this->form->post(); } - - $grav['form'] = $this->form; } } @@ -80,7 +78,7 @@ public function onTwigSiteVariables() return; } - $this->grav['twig']->twig_vars['form'] = $this->grav['form']; + $this->grav['twig']->twig_vars['form'] = $this->form; } /** From a03ff7df37355a1b0095b7d02bbc42a97b48885c Mon Sep 17 00:00:00 2001 From: Djamil Legato Date: Wed, 24 Sep 2014 15:05:16 -0700 Subject: [PATCH 05/11] Updated blueprints with new meta syntax and removed VERSION file no longer needed. --- VERSION | 1 - blueprints.yaml | 11 +++++++++-- 2 files changed, 9 insertions(+), 3 deletions(-) delete mode 100644 VERSION diff --git a/VERSION b/VERSION deleted file mode 100644 index 3eefcb9d..00000000 --- a/VERSION +++ /dev/null @@ -1 +0,0 @@ -1.0.0 diff --git a/blueprints.yaml b/blueprints.yaml index e383a7cf..36078d6b 100644 --- a/blueprints.yaml +++ b/blueprints.yaml @@ -1,6 +1,13 @@ -name: Form Handling Plugin +name: Form version: 1.0.0 -description: Enables forms. +description: Enables the forms handling +icon: check-square +author: + name: Team Grav + email: devs@getgrav.org + url: http://getgrav.org +keywords: plugin, form + validation: strict form: From 8a85d77adf564619038064933136fe9b49044d1b Mon Sep 17 00:00:00 2001 From: Matias Griese Date: Wed, 1 Oct 2014 21:28:33 +0300 Subject: [PATCH 06/11] Update code to use new classes --- classes/form.php | 8 ++++---- form.php | 18 +++++++++--------- 2 files changed, 13 insertions(+), 13 deletions(-) diff --git a/classes/form.php b/classes/form.php index 28a12904..2c446096 100644 --- a/classes/form.php +++ b/classes/form.php @@ -1,10 +1,10 @@ $this->form ); - $file = File\General::instance(DATA_DIR . $this->form->name . '/' . $filename); + $file = File::instance(DATA_DIR . $this->form->name . '/' . $filename); $body = $twig->processString( !empty($params['body']) ? $params['body'] : '{% include "forms/data.txt.twig" %}', $vars From 7d8ae5d6e6871d1c08b1ac93b1d6fe6b62a1f87c Mon Sep 17 00:00:00 2001 From: Matias Griese Date: Fri, 10 Oct 2014 12:27:41 +0300 Subject: [PATCH 07/11] Bluprints: Move validation parameter inside the form --- blueprints.yaml | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/blueprints.yaml b/blueprints.yaml index 36078d6b..b2fb596c 100644 --- a/blueprints.yaml +++ b/blueprints.yaml @@ -8,9 +8,8 @@ author: url: http://getgrav.org keywords: plugin, form -validation: strict - form: + validation: strict fields: enabled: type: toggle From 91d2ed71b090a70cd790868dc00cbb333bf6bb51 Mon Sep 17 00:00:00 2001 From: Andy Miller Date: Sun, 30 Nov 2014 20:01:40 -0700 Subject: [PATCH 08/11] PSR fixes --- form.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/form.php b/form.php index 475b5a30..f9998ecf 100644 --- a/form.php +++ b/form.php @@ -26,7 +26,8 @@ class FormPlugin extends Plugin /** * @return array */ - public static function getSubscribedEvents() { + public static function getSubscribedEvents() + { return [ 'onPageInitialized' => ['onPageInitialized', 0], 'onTwigTemplatePaths' => ['onTwigTemplatePaths', 0], From 29b11842a2164afad9514508bab86ae36715beb2 Mon Sep 17 00:00:00 2001 From: Andy Miller Date: Thu, 5 Feb 2015 15:11:59 -0700 Subject: [PATCH 09/11] HHVM support --- classes/form.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/classes/form.php b/classes/form.php index 2c446096..bd409bc3 100644 --- a/classes/form.php +++ b/classes/form.php @@ -88,7 +88,7 @@ public function post() $action = \key($data); $data = $data[$action]; } - self::$grav->fireEvent('onFormProcessed', $this, $action, $data); + self::getGrav()->fireEvent('onFormProcessed', $this, $action, $data); } } else { // Default action. From b399fd8d3953c4be2b03856a88b1dd19ff522639 Mon Sep 17 00:00:00 2001 From: Andy Miller Date: Tue, 21 Jul 2015 22:07:52 -0600 Subject: [PATCH 10/11] added title --- templates/forms/fields/password/password.html.twig | 1 + templates/forms/fields/text/text.html.twig | 2 ++ 2 files changed, 3 insertions(+) diff --git a/templates/forms/fields/password/password.html.twig b/templates/forms/fields/password/password.html.twig index c0a140f6..ad421f20 100644 --- a/templates/forms/fields/password/password.html.twig +++ b/templates/forms/fields/password/password.html.twig @@ -14,6 +14,7 @@ name="{{ (scope ~ field.name)|fieldName }}" value="{{ value|join(', ') }}" {% if field.placeholder %}placeholder="{{ field.placeholder }}"{% endif %} + {% if field.title %}title="{{ field.title }}"{% endif %} {% if field.autofocus in ['on', 'true', 1] %}autofocus="autofocus"{% endif %} {% if field.novalidate in ['on', 'true', 1] %}novalidate="novalidate"{% endif %} {% if field.autocomplete in ['on', 'off'] %}autocomplete="{{ field.autocomplete }}"{% endif %} diff --git a/templates/forms/fields/text/text.html.twig b/templates/forms/fields/text/text.html.twig index a8bc6863..cec6986c 100644 --- a/templates/forms/fields/text/text.html.twig +++ b/templates/forms/fields/text/text.html.twig @@ -16,11 +16,13 @@ name="{{ (scope ~ field.name)|fieldName }}" value="{{ value|join(', ') }}" {% if field.placeholder %}placeholder="{{ field.placeholder }}"{% endif %} + {% if field.title %}title="{{ field.title }}"{% endif %} {% if field.autofocus in ['on', 'true', 1] %}autofocus="autofocus"{% endif %} {% if field.novalidate in ['on', 'true', 1] %}novalidate="novalidate"{% endif %} {% if field.autocomplete in ['on', 'off'] %}autocomplete="{{ field.autocomplete }}"{% endif %} {% if field.validate.required in ['on', 'true', 1] %}required="required"{% endif %} {% if field.validate.pattern %}pattern="{{ field.validate.pattern }}"{% endif %} + /> From 95920a36167cf8f9c5fd8073dd39bc0232abfa49 Mon Sep 17 00:00:00 2001 From: Andy Miller Date: Tue, 4 Aug 2015 12:45:38 -0600 Subject: [PATCH 11/11] getting ready for release --- CHANGELOG.md | 5 +++++ README.md | 23 ++++++++++++++++++++--- blueprints.yaml | 3 +++ 3 files changed, 28 insertions(+), 3 deletions(-) create mode 100644 CHANGELOG.md diff --git a/CHANGELOG.md b/CHANGELOG.md new file mode 100644 index 00000000..24a0762c --- /dev/null +++ b/CHANGELOG.md @@ -0,0 +1,5 @@ +# v0.1.0 +## 08/04/2015 + +1. [](#new) + * ChangeLog started... diff --git a/README.md b/README.md index 113a9336..45ed58f5 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,21 @@ -grav-plugin-form -================ +# Grav Form Plugin -Grav Form Plugin +The **form plugin** for [Grav](http://github.com/getgrav/grav) adds the ability to create and use forms. This is currently used extensively by the **admin** and **login** plugins. + +| IMPORTANT!!! This plugin is currently in development as is to be considered a **beta release**. As such, use this in a production environment **at your own risk!**. More features will be added in the future. + +# Installation + +The form plugin is easy to install with GPM. + +``` +$ bin/gpm install form +``` + +# Configuration + +Simply copy the `user/plugins/forms/forms.yaml` into `user/config/plugins/forms.yaml` and make your modifications. + +``` +enabled: true +``` diff --git a/blueprints.yaml b/blueprints.yaml index b2fb596c..70c6cb12 100644 --- a/blueprints.yaml +++ b/blueprints.yaml @@ -7,6 +7,9 @@ author: email: devs@getgrav.org url: http://getgrav.org keywords: plugin, form +homepage: https://github.com/getgrav/grav-plugin-form +bugs: https://github.com/getgrav/grav-plugin-form/issues +license: MIT form: validation: strict