Files
fixclean f4ce7f360d feat: implement package 1 session and validation feedback
- 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
2026-02-18 09:40:59 +01:00

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;