summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorDaniel Weipert <code@drogueronin.de>2022-01-06 01:36:07 +0100
committerDaniel Weipert <code@drogueronin.de>2022-01-10 11:29:13 +0100
commit75f3e8ab4b3d65d6eba16575ca0a4a669b7e27ac (patch)
treeb9b60559afbfff883dfe8aaf7b70e9b8b6bc1c4f /src
parent0b0af86264107a9c95ff37a1b3fdc845aa7a27b2 (diff)
Validate fields with custom function
Diffstat (limited to 'src')
-rw-r--r--src/App.php19
1 files changed, 16 insertions, 3 deletions
diff --git a/src/App.php b/src/App.php
index 1a12f6a..0c0773b 100644
--- a/src/App.php
+++ b/src/App.php
@@ -9,6 +9,8 @@ use Yosymfony\Toml\TomlBuilder;
class App
{
+ public string $formPath;
+
/**
* App constructor.
*/
@@ -42,7 +44,7 @@ class App
// GET
if ($method == 'GET') {
if (str_ends_with($path, '/fields')) {
- $formPath = $contentRoot . str_replace('/fields', '', $path);
+ $this->formPath = $formPath = $contentRoot . str_replace('/fields', '', $path);
$fields = $this->buildFields($formPath, $_GET['page'] ?? null);
@@ -62,7 +64,7 @@ class App
// POST
else if ($method == 'POST') {
if (str_ends_with($path, '/validate')) {
- $formPath = $contentRoot . str_replace('/validate', '', $path);
+ $this->formPath = $formPath = $contentRoot . str_replace('/validate', '', $path);
$fields = $this->buildFields($formPath, $_GET['page'] ?? null);
@@ -70,7 +72,7 @@ class App
}
else if (str_ends_with($path, '/submit')) {
- $formPath = $contentRoot . str_replace('/submit', '', $path);
+ $this->formPath = $formPath = $contentRoot . str_replace('/submit', '', $path);
$fields = $this->buildFields($formPath);
@@ -268,6 +270,11 @@ class App
$field['is_valid'] = false;
}
+ $validationFunctionName = 'validate_' . basename($this->formPath) . '_' . $field['name'];
+ if (function_exists($validationFunctionName)) {
+ $field = call_user_func($validationFunctionName, $field, $value);
+ }
+
return $field;
}
@@ -288,6 +295,12 @@ class App
$config['api']['keys'] = $apiKeys;
}
+ // include custom functions
+ $functionsFile = $currentDirectory . '/config/functions.php';
+ if (file_exists($functionsFile)) {
+ include_once $functionsFile;
+ }
+
if (str_ends_with($currentDirectory, '/' . basename($_ENV['app']['contentFolderPath'])) || $currentDirectory == '/') {
break;
}