Skip to content

Commit

Permalink
bug fixes for form process manipulation and named seqs
Browse files Browse the repository at this point in the history
  • Loading branch information
finanalyst committed Jun 6, 2018
1 parent ddc46a9 commit 6b95d5c
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 18 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
#v1.0.4
## 6 June 2018
1. [](#bug fix)
* fixed main form 'process' analysis for processes after sequence
* take name of named sequences from page header, and do not take from `new_page` parameter.

#v1.0.3
## 13 May 2018
1. [](#update)
Expand Down
8 changes: 5 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -68,11 +68,13 @@ The contents of these files is as follows
```yaml
---
title: User data
slug: start
sequence:
banner: true
content: above
cache_enable: false
form:
name: user-data`
name: user-data
fields:
- name: location
type: text
Expand All @@ -96,7 +98,7 @@ form:
- address-card
- video-camera
- thumbs-up
- display: start/final
- redirect: start/final
---
# Collect Data
```
Expand Down Expand Up @@ -176,8 +178,8 @@ the first form (the one that has `sequence` as a process).
- `sequence.name` must be included in the header of every sub-page of the sequence.
- The `next_page` process must be given the sequence name.
- If only one sequence is needed, `sequence.name` may be omitted, in which case, the name defaults to `default`.
- With only one sequence `next_page` should be set to `true`.
1. In order to stop a sequence, and return to the first stage with no data in the form, include a `submit` button, together with the task `sequence_reset`.
1. It is best to specify `slug: route_name` in the root `sequence` page if it is desired for the sequence to end, as in the example, with a redirect to a different page. In the example the first sequence has `slug: start` and the **Form** process has `redirect: start/final`

## To Do

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.3
version: 1.0.4
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
22 changes: 8 additions & 14 deletions sequential-form.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,9 @@ public function onFormProcessed(Event $event)
switch ($action) {
case 'next_page':
$seq_name = 'sequence_';
if ($params == true ) $seq_name .= 'default';
else $seq_name .= $params;
$header = $this->grav['page']->header()->{'sequence'};
if ( isset($header['name']) ) $seq_name .= $header['name'];
else $seq_name .= 'default';
$sumForm = $this->grav['session']->getFlashObject( $seq_name ); // this also removes the object from the session
// trap a sequence reset button
if (isset($_POST['task']) && $_POST['task'] == 'sequence_reset' ) {
Expand All @@ -87,18 +88,11 @@ public function onFormProcessed(Event $event)
$rp = new ReflectionProperty('Grav\Plugin\Form', 'items');
$rp->setAccessible(true);
$items = $rp->getValue($sumForm);
$procs = $items['process'][0];
$add = false;
$newproc = [];
foreach ($procs as $action => $data) {
if (is_numeric($action)) {
$action = \key($data);
$data = $data[$action];
}
if($add) array_push($newproc, array($action => $data));
$add |= $action == 'sequence';
}
$items['process'] = $newproc;
$procs = $items['process'];
do {
$action = array_shift($procs);
} while ( \key($action) !== 'sequence' );
$items['process'] = $procs;
$rp->setValue($sumForm,$items);
$pages = $this->grav['pages'];
$page = $pages->dispatch($sequence['origin'], true);
Expand Down

0 comments on commit 6b95d5c

Please sign in to comment.