summaryrefslogtreecommitdiffstats
path: root/inc
diff options
context:
space:
mode:
authorSimon Rettberg2025-05-09 16:00:54 +0200
committerSimon Rettberg2025-05-09 16:00:54 +0200
commit3b1fea01fdbb0c30dfe6030740c14e671c3ca0e3 (patch)
treea94b877b6380ed11f7a20f3f86c023c104cd4fc1 /inc
parentUse http_response_code() instead of header(), add a few missing repsonse codes (diff)
downloadslx-admin-3b1fea01fdbb0c30dfe6030740c14e671c3ca0e3.tar.gz
slx-admin-3b1fea01fdbb0c30dfe6030740c14e671c3ca0e3.tar.xz
slx-admin-3b1fea01fdbb0c30dfe6030740c14e671c3ca0e3.zip
[inc/Request] HTTP error code, avoid redirect, return text for API mode
Diffstat (limited to 'inc')
-rw-r--r--inc/request.inc.php34
1 files changed, 22 insertions, 12 deletions
diff --git a/inc/request.inc.php b/inc/request.inc.php
index e126d551..54884475 100644
--- a/inc/request.inc.php
+++ b/inc/request.inc.php
@@ -70,22 +70,32 @@ class Request
private static function handle(&$array, $key, $default, $type)
{
- if (!array_key_exists($key, $array)) {
- if ($default === self::REQUIRED || $default === self::REQUIRED_EMPTY) {
- Message::addError('main.parameter-missing', $key);
- if (API)
- exit;
- Util::redirect('?do=' . $_REQUEST['do']);
+ $err = false;
+ if ($default === self::REQUIRED_EMPTY || $default === self::REQUIRED) {
+ if (!array_key_exists($key, $array)) {
+ $err = 'missing';
+ } elseif ($default === self::REQUIRED && $array[$key] === '') {
+ $err = 'empty';
}
- return $default;
}
- if ($default === self::REQUIRED && $array[$key] === '') {
- Message::addError('main.parameter-empty', $key);
+ if ($err !== false) {
+ http_response_code(400);
if (API)
- exit;
- Util::redirect('?do=' . $_REQUEST['do']);
+ die("Parameter $key $err");
+ if ($err === 'missing') { // Explicit so translate module finds the addError calls
+ Message::addError('main.parameter-missing', $key);
+ } else {
+ Message::addError('main.parameter-empty', $key);
+ }
+ Render::addFooter('<button class="btn btn-danger" style="margin:20px" onclick="history.back()">Back</button>');
+ Render::output();
+ exit;
+ }
+ if (!isset($array[$key]))
+ return $default;
+ if ($type !== false) {
+ settype($array[$key], $type);
}
- if ($type !== false) settype($array[$key], $type);
return $array[$key];
}