| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158 |
- <?php
- declare(strict_types=1);
- use App\App\Bootstrap;
- use App\Form\FormSchema;
- use App\Security\Csrf;
- require __DIR__ . '/src/autoload.php';
- Bootstrap::init();
- $schema = new FormSchema();
- $steps = $schema->getSteps();
- $csrf = Csrf::token();
- $app = Bootstrap::config('app');
- $disclaimerTitle = (string) ($app['disclaimer']['title'] ?? 'Hinweis');
- $disclaimerText = (string) ($app['disclaimer']['text'] ?? '');
- $disclaimerAcceptLabel = (string) ($app['disclaimer']['accept_label'] ?? 'Hinweis gelesen, weiter');
- /** @param array<string, mixed> $field */
- function renderField(array $field): void
- {
- $key = htmlspecialchars((string) $field['key']);
- $label = htmlspecialchars((string) $field['label']);
- $type = (string) ($field['type'] ?? 'text');
- $required = ((bool) ($field['required'] ?? false)) ? 'required' : '';
- echo '<div class="field" data-field="' . $key . '">';
- if ($type === 'checkbox') {
- echo '<label class="checkbox-label"><input type="checkbox" name="form_data[' . $key . ']" value="1" ' . $required . '> ' . $label . '</label>';
- } else {
- echo '<label for="' . $key . '">' . $label . '</label>';
- if ($type === 'textarea') {
- echo '<textarea id="' . $key . '" name="form_data[' . $key . ']" ' . $required . '></textarea>';
- } elseif ($type === 'select') {
- echo '<select id="' . $key . '" name="form_data[' . $key . ']" ' . $required . '>';
- echo '<option value="">Bitte wählen</option>';
- foreach (($field['options'] ?? []) as $option) {
- if (!is_array($option)) {
- continue;
- }
- $value = htmlspecialchars((string) ($option['value'] ?? ''));
- $optLabel = htmlspecialchars((string) ($option['label'] ?? ''));
- echo '<option value="' . $value . '">' . $optLabel . '</option>';
- }
- echo '</select>';
- } elseif ($type === 'file') {
- $accept = htmlspecialchars((string) ($field['accept'] ?? ''));
- $fileInputId = $key . '_file';
- $cameraInputId = $key . '_camera';
- echo '<div class="upload-control" data-upload-key="' . $key . '">';
- echo '<div class="upload-actions">';
- echo '<label class="upload-action-btn" for="' . $fileInputId . '">Datei auswählen</label>';
- echo '<label class="upload-action-btn upload-action-btn-camera" for="' . $cameraInputId . '">Foto aufnehmen</label>';
- echo '</div>';
- echo '<input id="' . $fileInputId . '" class="upload-native-input" type="file" name="' . $key . '" accept="' . $accept . '">';
- echo '<input id="' . $cameraInputId . '" class="upload-native-input" type="file" name="' . $key . '__camera" accept="image/*" capture="environment">';
- echo '<p class="upload-selected" data-upload-selected="' . $key . '">Keine Datei gewählt</p>';
- echo '</div>';
- echo '<div class="upload-list" data-upload-list="' . $key . '"></div>';
- } else {
- $inputType = htmlspecialchars($type);
- echo '<input id="' . $key . '" type="' . $inputType . '" name="form_data[' . $key . ']" ' . $required . '>';
- }
- }
- if (isset($field['required_if']) && is_array($field['required_if'])) {
- $depField = htmlspecialchars((string) ($field['required_if']['field'] ?? ''));
- $depValue = htmlspecialchars((string) ($field['required_if']['equals'] ?? ''));
- echo '<small class="hint">Pflicht, wenn ' . $depField . ' = ' . $depValue . '.</small>';
- }
- echo '<div class="error" data-error-for="' . $key . '"></div>';
- echo '</div>';
- }
- ?><!doctype html>
- <html lang="de">
- <head>
- <meta charset="utf-8">
- <meta name="viewport" content="width=device-width, initial-scale=1">
- <title><?= htmlspecialchars((string) $app['project_name']) ?></title>
- <link rel="stylesheet" href="/assets/css/tokens.css">
- <link rel="stylesheet" href="/assets/css/base.css">
- </head>
- <body>
- <main class="container">
- <h1>Digitaler Mitgliedsantrag Feuerwehrverein</h1>
- <section id="disclaimerSection" class="card">
- <h2><?= htmlspecialchars($disclaimerTitle) ?></h2>
- <p class="disclaimer-text"><?= nl2br(htmlspecialchars($disclaimerText)) ?></p>
- <button id="acceptDisclaimerBtn" type="button"><?= htmlspecialchars($disclaimerAcceptLabel) ?></button>
- </section>
- <section id="startSection" class="card hidden">
- <h2>Start</h2>
- <p id="startIntroText">Bitte E-Mail eingeben. Bestehende Entwürfe werden automatisch geladen.</p>
- <form id="startForm" novalidate>
- <input type="hidden" name="csrf" value="<?= htmlspecialchars($csrf) ?>">
- <div class="hp-field" aria-hidden="true">
- <label for="website">Website</label>
- <input id="website" type="text" name="website" autocomplete="off" tabindex="-1">
- </div>
- <div class="field" id="startEmailField">
- <label for="startEmail">E-Mail</label>
- <input id="startEmail" type="email" name="email" required inputmode="email" autocomplete="email">
- </div>
- <div class="inline-actions" id="startActions">
- <button id="startSubmitBtn" type="submit">Formular laden</button>
- </div>
- <div id="compactStatusBox" class="compact-status hidden">
- <p><strong>E-Mail:</strong> <span id="statusEmailValue">-</span></p>
- <p><strong>Speicherstatus:</strong> <span id="draftStatusValue">Noch nicht gespeichert</span></p>
- <button id="resetDataBtn" type="button">Gespeicherte Daten löschen und neu starten</button>
- </div>
- <p id="feedbackMessage" class="status-text" role="status" aria-live="polite"></p>
- </form>
- </section>
- <section id="wizardSection" class="card hidden">
- <h2>Mitgliedsantrag</h2>
- <div id="progress" class="progress"></div>
- <form id="applicationForm" enctype="multipart/form-data" novalidate>
- <input type="hidden" name="csrf" value="<?= htmlspecialchars($csrf) ?>">
- <input type="hidden" id="applicationEmail" name="email" value="">
- <input type="hidden" id="applicationWebsite" name="website" value="">
- <?php foreach ($steps as $index => $step): ?>
- <section class="step hidden" data-step="<?= $index + 1 ?>">
- <h3>Schritt <?= $index + 1 ?>: <?= htmlspecialchars((string) ($step['title'] ?? '')) ?></h3>
- <p><?= htmlspecialchars((string) ($step['description'] ?? '')) ?></p>
- <?php foreach (($step['fields'] ?? []) as $field): ?>
- <?php if (is_array($field)) { renderField($field); } ?>
- <?php endforeach; ?>
- </section>
- <?php endforeach; ?>
- <div class="wizard-actions">
- <button type="button" id="prevBtn">Zurück</button>
- <button type="button" id="nextBtn">Weiter</button>
- <button type="button" id="submitBtn" class="hidden">Verbindlich absenden</button>
- </div>
- </form>
- </section>
- </main>
- <script>
- window.APP_BOOT = {
- steps: <?= json_encode($steps, JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES) ?>,
- csrf: <?= json_encode($csrf, JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES) ?>,
- contactEmail: <?= json_encode((string) ($app['contact_email'] ?? ''), JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES) ?>
- };
- </script>
- <script src="/assets/js/form.js"></script>
- </body>
- </html>
|