summaryrefslogtreecommitdiff
path: root/src/Controllers/SubmissionController.php
diff options
context:
space:
mode:
Diffstat (limited to 'src/Controllers/SubmissionController.php')
-rw-r--r--src/Controllers/SubmissionController.php24
1 files changed, 14 insertions, 10 deletions
diff --git a/src/Controllers/SubmissionController.php b/src/Controllers/SubmissionController.php
index 2c3d603..8d7d9e6 100644
--- a/src/Controllers/SubmissionController.php
+++ b/src/Controllers/SubmissionController.php
@@ -3,13 +3,21 @@
namespace FlatFileForms\Controllers;
use FlatFileForms\Builder;
+use FlatFileForms\Form;
+use FlatFileForms\HookManager;
use FlatFileForms\Validator;
-use Yosymfony\Toml\TomlBuilder;
+use Symfony\Component\Yaml\Yaml;
class SubmissionController
{
public function submit(Builder $builder, Validator $validator, string $formPath): array
{
+ /**@var HookManager $hooks*/
+ global $hooks;
+
+ /**@var Form $form*/
+ global $form;
+
$fields = $builder->buildFields();
// run through validation
@@ -21,23 +29,19 @@ class SubmissionController
if (empty($result['error'])) {
$date = new \Datetime();
$entry = [
- 'fields' => $_POST,
'date' => $date->format('c'),
+ 'fields' => $_POST,
];
- $entryBuilder = new TomlBuilder();
- $entryBuilder->addValue('date', $entry['date']);
- $entryBuilder->addTable('fields');
- foreach ($entry['fields'] as $entryKey => $entryValue) {
- $entryBuilder->addValue($entryKey, $entryValue);
- }
+ $entry = $hooks->applyFilter("submit:{$form->name}:entry", $entry);
+ $entry = $hooks->applyFilter('submit:entry', $entry);
$entryDirectory = $formPath . '/entries/' . $date->format('Y/m/d');
@mkdir($entryDirectory, 0774, true);
- $entryFilename = $date->format('Ymd_Hi_') . hash('adler32', serialize($entry)) . '.toml';
+ $entryFilename = $date->format('Ymd_Hi_') . hash('adler32', serialize($entry)) . '.yaml';
file_put_contents(
$entryDirectory . '/' . $entryFilename,
- $entryBuilder->getTomlString()
+ Yaml::dump($entry, 4)
);
}
else {