Skip to content

Commit

Permalink
Added ability to process current form on any other page
Browse files Browse the repository at this point in the history
  • Loading branch information
rhukster committed Mar 17, 2017
1 parent 40c2abc commit 6996e84
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions form.php
Original file line number Diff line number Diff line change
Expand Up @@ -189,16 +189,16 @@ public function onPagesInitialized()
$current_form_name = $this->getFormName($this->grav['page']);
$this->json_response = [];

if ($form = $this->getFormByName($current_form_name)) {
if ($this->form = $this->getFormByName($current_form_name)) {
if ($this->grav['uri']->extension() === 'json' && isset($_POST['__form-file-uploader__'])) {
$this->json_response = $form->uploadFiles();
$this->json_response = $this->form->uploadFiles();
} else {
$form->post();
$this->form->post();
$submitted = true;
}
} elseif (isset($this->grav['page']->header()->form)) {
$form = new Form($this->grav['page']);
$form->post();
$this->form = new Form($this->grav['page']);
$this->form->post();
$submitted = true;
}
}
Expand Down Expand Up @@ -259,7 +259,9 @@ public function onTwigVariables(Event $event = null)
$current_page_route = $this->getCurrentPageRoute();
$found_forms = [];

if (!isset($this->grav['twig']->twig_vars['form'])) {
if (isset($this->form)) {
$this->grav['twig']->twig_vars['form'] = $this->form;
} elseif (!isset($this->grav['twig']->twig_vars['form'])) {
if (isset($this->forms[$page_route])) {
$found_forms = $this->forms[$page_route];
} elseif (isset($this->forms[$current_page_route])) {
Expand Down

0 comments on commit 6996e84

Please sign in to comment.