summaryrefslogtreecommitdiff
path: root/src/application/mystic/forum/utils
diff options
context:
space:
mode:
authorJonas Kohl2024-09-18 23:05:35 +0200
committerJonas Kohl2024-09-18 23:05:35 +0200
commit01454544896827113e49db0d2848b5aab6ce14ae (patch)
tree9487c3d45a04d350bca2ed8401a797ed69cd7e8a /src/application/mystic/forum/utils
parenta65d424263adfbff9629c7d91a613e4504c84613 (diff)
Many changes
Diffstat (limited to 'src/application/mystic/forum/utils')
-rw-r--r--src/application/mystic/forum/utils/RequestUtils.php24
1 files changed, 16 insertions, 8 deletions
diff --git a/src/application/mystic/forum/utils/RequestUtils.php b/src/application/mystic/forum/utils/RequestUtils.php
index 6599052..796a476 100644
--- a/src/application/mystic/forum/utils/RequestUtils.php
+++ b/src/application/mystic/forum/utils/RequestUtils.php
@@ -10,6 +10,8 @@ use mystic\forum\orm\User;
final class RequestUtils {
use StaticClass;
+ private static ?string $formErrorDestination = null;
+
public static function getRequestMethod(): string {
return strtoupper($_SERVER["REQUEST_METHOD"] ?? "GET");
}
@@ -27,12 +29,12 @@ final class RequestUtils {
}
}
- public static function getRequiredField(string $field): string {
+ public static function getRequiredField(string $field, string $formId): string {
$fieldValue = $_POST[$field] ?? null;
if ($fieldValue === null) {
//http_response_code(400);
//Messaging::error("Missing required field $field");
- RequestUtils::triggerFormError("Missing required field '$field'");
+ RequestUtils::triggerFormError("Missing required field '$field'", $formId);
//exit;
}
return $fieldValue;
@@ -43,18 +45,24 @@ final class RequestUtils {
$_SESSION["lastForm_uri"] = $_SERVER["REQUEST_URI"];
}
- public static function triggerFormError(string $message, ?string $next = null): never {
- $next ??= $_SERVER["REQUEST_URI"];
- $_SESSION["formError"] = $message;
+ public static function setFormErrorDestination(?string $dest): ?string {
+ $prev = self::$formErrorDestination;
+ self::$formErrorDestination = $dest;
+ return $prev;
+ }
+
+ public static function triggerFormError(string $message, string $formId, ?string $next = null): never {
+ $next ??= self::$formErrorDestination ?? $_SERVER["REQUEST_URI"];
+ $_SESSION["formError/$formId"] = $message;
// store last form submission
self::storeForm();
header("Location: $next");
exit;
}
- public static function getAndClearFormError(): ?string {
- $err = $_SESSION["formError"] ?? null;
- unset($_SESSION["formError"]);
+ public static function getAndClearFormError(string $formId): ?string {
+ $err = $_SESSION["formError/$formId"] ?? null;
+ unset($_SESSION["formError/$formId"]);
return $err;
}