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
This commit is contained in:
@@ -12,21 +12,5 @@
|
||||
| Session: <?php echo session_id() !== '' ? 'aktiv' : 'inaktiv'; ?>
|
||||
</p>
|
||||
</footer>
|
||||
|
||||
<?php if (!empty($_SESSION['success']) || !empty($_SESSION['error'])): ?>
|
||||
<script>
|
||||
(function () {
|
||||
const success = <?php echo json_encode($_SESSION['success'] ?? '', JSON_UNESCAPED_UNICODE); ?>;
|
||||
const error = <?php echo json_encode($_SESSION['error'] ?? '', JSON_UNESCAPED_UNICODE); ?>;
|
||||
if (success) {
|
||||
alert(success);
|
||||
}
|
||||
if (error) {
|
||||
alert(error);
|
||||
}
|
||||
})();
|
||||
</script>
|
||||
<?php unset($_SESSION['success'], $_SESSION['error']); ?>
|
||||
<?php endif; ?>
|
||||
</body>
|
||||
</html>
|
||||
|
||||
@@ -64,4 +64,60 @@
|
||||
</nav>
|
||||
</header>
|
||||
|
||||
<?php
|
||||
$flashMessages = [];
|
||||
|
||||
$successMessage = trim((string)($_SESSION['success'] ?? ''));
|
||||
if ($successMessage !== '') {
|
||||
$flashMessages[] = [
|
||||
'type' => 'success',
|
||||
'text' => $successMessage,
|
||||
];
|
||||
}
|
||||
|
||||
$errorMessage = trim((string)($_SESSION['error'] ?? ''));
|
||||
if ($errorMessage !== '') {
|
||||
$flashMessages[] = [
|
||||
'type' => 'error',
|
||||
'text' => $errorMessage,
|
||||
];
|
||||
}
|
||||
|
||||
$validationErrors = $_SESSION['validation_errors'] ?? [];
|
||||
if (!is_array($validationErrors)) {
|
||||
$validationErrors = [];
|
||||
}
|
||||
$validationErrors = array_values(array_filter(array_map(static function ($entry) {
|
||||
return trim((string)$entry);
|
||||
}, $validationErrors), static function ($entry) {
|
||||
return $entry !== '';
|
||||
}));
|
||||
|
||||
if (!empty($validationErrors)) {
|
||||
$flashMessages[] = [
|
||||
'type' => 'error',
|
||||
'text' => 'Bitte pruefe die Eingaben:',
|
||||
'details' => $validationErrors,
|
||||
];
|
||||
}
|
||||
|
||||
unset($_SESSION['success'], $_SESSION['error'], $_SESSION['validation_errors']);
|
||||
?>
|
||||
|
||||
<main>
|
||||
<?php if (!empty($flashMessages)): ?>
|
||||
<section class="flash-stack" aria-live="polite">
|
||||
<?php foreach ($flashMessages as $message): ?>
|
||||
<article class="flash-message flash-message--<?php echo htmlspecialchars((string)$message['type']); ?>">
|
||||
<p class="flash-message__text"><?php echo htmlspecialchars((string)($message['text'] ?? '')); ?></p>
|
||||
<?php if (!empty($message['details']) && is_array($message['details'])): ?>
|
||||
<ul class="flash-message__list">
|
||||
<?php foreach ($message['details'] as $detail): ?>
|
||||
<li><?php echo htmlspecialchars((string)$detail); ?></li>
|
||||
<?php endforeach; ?>
|
||||
</ul>
|
||||
<?php endif; ?>
|
||||
</article>
|
||||
<?php endforeach; ?>
|
||||
</section>
|
||||
<?php endif; ?>
|
||||
|
||||
Reference in New Issue
Block a user