Skip to content

Commit

Permalink
add onFormValidationError to point at first sequence.md form, not a s…
Browse files Browse the repository at this point in the history
…ubform
  • Loading branch information
finanalyst committed Jun 26, 2018
1 parent efbbb0e commit 0469e5c
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 12 deletions.
8 changes: 7 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,14 @@
#v1.0.6
## 26 June 2018
1. [](#bugfix)
* added own 'onFormValidationError' function so that errors in subprocesses are
handled in the first sequence.md form, and not in the subform.

#v1.0.5
## 8 June 2018
1. [](#bug fix)
* update to slug when on home page.

#v1.0.4
## 6 June 2018
1. [](#bug fix)
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: Sequential Form
version: 1.0.5
version: 1.0.6
description: A sequence of pages, each with a form is linked, with all form data processed according to the final process
icon: link
author:
Expand Down
18 changes: 17 additions & 1 deletion sequential-form.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@ public function onPluginsInitialized()
$this->enable([
'onTwigTemplatePaths' => ['onTwigTemplatePaths',0],
'onTwigSiteVariables' => ['onTwigSiteVariables',0],
'onFormProcessed' => ['onFormProcessed', 0]
'onFormProcessed' => ['onFormProcessed', 0],
'onFormValidationError' => ['onFormValidationError', 0]
]);
}

Expand Down Expand Up @@ -136,4 +137,19 @@ public function onFormProcessed(Event $event)
break;
}
}

public function onFormValidationError(Event $event)
{
$form = $event['form'];

if (isset($event['message'])) {
$form->status = 'error';
$form->message = $event['message'];
$form->messages = $event['messages'];
}
$twig = $this->grav['twig'];
$twig->twig_vars['form'] = $form;
// will return to initial sequence form.
$event->stopPropagation();
}
}
23 changes: 14 additions & 9 deletions templates/sequence.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,19 @@
{% endif %}

{% block content %}
{% if page.header.sequence.banner %}
{% include "partials/banner.html.twig" with seq_data %}
{% endif %}
{% if page.header.sequence.content is same as( 'above' ) %}
{{ content|raw }}
{% endif %}
{% include "forms/form.html.twig" %}
{% if not page.header.sequence.content is same as( 'above' ) %}
{{ content|raw }}
{% if form.error %}
{{ form.message }}
{% else %}
{% if page.header.sequence.banner %}
{% include "partials/banner.html.twig" with seq_data %}
{% endif %}

{% if page.header.sequence.content is same as( 'above' ) %}
{{ content|raw }}
{% endif %}
{% include "forms/form.html.twig" %}
{% if not page.header.sequence.content is same as( 'above' ) %}
{{ content|raw }}
{% endif %}
{% endif %}
{% endblock %}

0 comments on commit 0469e5c

Please sign in to comment.