- add session validation_errors bootstrap initialization - render global flash + validation messages in header - remove footer alert-based flash handling - persist structured validation errors across save handlers - mark NEXT_STEPS package 1 tasks as done
46 lines
1.0 KiB
PHP
46 lines
1.0 KiB
PHP
<?php
|
|
/**
|
|
* app/modules/locations/save.php
|
|
*/
|
|
|
|
if ($_SERVER['REQUEST_METHOD'] !== 'POST') {
|
|
header('Location: ?module=locations&action=list');
|
|
exit;
|
|
}
|
|
|
|
$locationId = (int)($_POST['id'] ?? 0);
|
|
$name = trim($_POST['name'] ?? '');
|
|
$comment = trim($_POST['comment'] ?? '');
|
|
|
|
$errors = [];
|
|
|
|
if (empty($name)) {
|
|
$errors[] = "Name ist erforderlich";
|
|
}
|
|
|
|
if (!empty($errors)) {
|
|
$_SESSION['error'] = implode(', ', $errors);
|
|
$_SESSION['validation_errors'] = $errors;
|
|
$redirectUrl = $locationId ? "?module=locations&action=edit&id=$locationId" : "?module=locations&action=edit";
|
|
header("Location: $redirectUrl");
|
|
exit;
|
|
}
|
|
|
|
if ($locationId > 0) {
|
|
$sql->set(
|
|
"UPDATE locations SET name = ?, comment = ? WHERE id = ?",
|
|
"ssi",
|
|
[$name, $comment, $locationId]
|
|
);
|
|
} else {
|
|
$sql->set(
|
|
"INSERT INTO locations (name, comment) VALUES (?, ?)",
|
|
"ss",
|
|
[$name, $comment]
|
|
);
|
|
}
|
|
|
|
$_SESSION['success'] = "Standort gespeichert";
|
|
header('Location: ?module=locations&action=list');
|
|
exit;
|