diff options
-rw-r--r-- | src/App.php | 27 | ||||
-rw-r--r-- | templates/form-paged/fields/_fields.toml | 13 | ||||
-rw-r--r-- | templates/form-paged/fields/email.toml | 7 | ||||
-rw-r--r-- | templates/form-paged/fields/name.toml | 6 | ||||
-rw-r--r-- | templates/form-paged/fields/second.toml | 3 | ||||
-rw-r--r-- | tests/Test.php | 12 |
6 files changed, 62 insertions, 6 deletions
diff --git a/src/App.php b/src/App.php index 107113a..a155017 100644 --- a/src/App.php +++ b/src/App.php @@ -171,9 +171,7 @@ class App throw new \Exception('Form has no page ' . $page); } - foreach ($parsed['page'][$page]['field'] as $key => $field) { - $fields[$key] = $this->buildSingleField($formPath, $key, $field); - } + $fields = $this->buildSinglePageFields($parsed['page'][$page], $formPath); } // else get all fields @@ -182,9 +180,7 @@ class App if (isset($parsed['page'])) { $pages = $parsed['page']; foreach ($pages as $pageKey => $pageFields) { - foreach ($pageFields['field'] as $key => $field) { - $fields[$pageKey][$key] = $this->buildSingleField($formPath, $key, $field); - } + $fields[$pageKey] = $this->buildSinglePageFields($pageFields, $formPath); } } @@ -200,6 +196,25 @@ class App } /** + * @param array $pageFields + * @param string $formPath + */ + public function buildSinglePageFields($pageFields, $formPath) + { + $fields = []; + + if (! empty($pageFields['file'])) { + $pageFields = array_replace_recursive($pageFields, Toml::parseFile($formPath . '/fields/' . $pageFields['file'])); + } + + foreach ($pageFields['field'] as $key => $field) { + $fields[$key] = $this->buildSingleField($formPath, $key, $field); + } + + return $fields; + } + + /** * @param string $formPath * @param string $key * @param string $field diff --git a/templates/form-paged/fields/_fields.toml b/templates/form-paged/fields/_fields.toml new file mode 100644 index 0000000..c0bfc7f --- /dev/null +++ b/templates/form-paged/fields/_fields.toml @@ -0,0 +1,13 @@ +[page.one.field.name] +file = "name.toml" + +[page.one.field.email] +file = "email.toml" +required = true + +[page.second] +file = "second.toml" + +[page.second.field.date] +required = true + diff --git a/templates/form-paged/fields/email.toml b/templates/form-paged/fields/email.toml new file mode 100644 index 0000000..3ef14e8 --- /dev/null +++ b/templates/form-paged/fields/email.toml @@ -0,0 +1,7 @@ +type = "email" +name = "email" +placeholder = "E-Mail" + +[attributes] +data-email = "test@example.org" + diff --git a/templates/form-paged/fields/name.toml b/templates/form-paged/fields/name.toml new file mode 100644 index 0000000..5c888b6 --- /dev/null +++ b/templates/form-paged/fields/name.toml @@ -0,0 +1,6 @@ +type = "text" +name = "name" + +[attributes] +data-value = 123 + diff --git a/templates/form-paged/fields/second.toml b/templates/form-paged/fields/second.toml new file mode 100644 index 0000000..bbc6ea7 --- /dev/null +++ b/templates/form-paged/fields/second.toml @@ -0,0 +1,3 @@ +[field.text] +placeholder = "Text placeholder" + diff --git a/tests/Test.php b/tests/Test.php index 2c81d46..798a74d 100644 --- a/tests/Test.php +++ b/tests/Test.php @@ -36,6 +36,9 @@ class Test extends TestCase [api] keys = ["1234"] + + [api.cors] + origins = [] EOF); # formname config @@ -84,9 +87,16 @@ class Test extends TestCase file = "email.toml" required = true + [page.second] + file = "second.toml" + [page.second.field.date] required = true EOF); + file_put_contents($contentRoot . '/customername/pagedform/fields/second.toml', <<<EOF + [field.text] + placeholder = "Text placeholder" + EOF); file_put_contents($contentRoot . '/customername/pagedform/fields/email.toml', <<<EOF type = "email" name = "email" @@ -162,6 +172,7 @@ class Test extends TestCase $this->assertArrayHasKey('name', $pagedformBody['one']); $this->assertArrayHasKey('email', $pagedformBody['one']); $this->assertArrayHasKey('date', $pagedformBody['second']); + $this->assertArrayHasKey('text', $pagedformBody['second']); // page=one $pagedformResponse = $this->request('GET', 'customername/pagedform/fields?page=one&key=' . $this->apiKey); @@ -175,6 +186,7 @@ class Test extends TestCase $pagedformBody = json_decode((string)$pagedformResponse->getBody(), true)['data']; $this->assertArrayNotHasKey('second', $pagedformBody); $this->assertArrayHasKey('date', $pagedformBody); + $this->assertArrayHasKey('text', $pagedformBody); } } |