| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145 |
- <?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');
- /** @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'] ?? ''));
- echo '<input id="' . $key . '" type="file" name="' . $key . '" accept="' . $accept . '">';
- echo '<small>Original-Dateiname wird übernommen und im System sicher gespeichert.</small>';
- 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="startSection" class="card">
- <h2>Start</h2>
- <p>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">
- <label for="startEmail">E-Mail</label>
- <input id="startEmail" type="email" name="email" required>
- </div>
- <button type="submit">Formular laden</button>
- </form>
- </section>
- <section id="blockedSection" class="card hidden">
- <h2>Antrag bereits vorhanden</h2>
- <p>Für diese E-Mail wurde bereits ein Antrag abgeschlossen. Für Rückfragen kontaktieren Sie bitte <?= htmlspecialchars((string) $app['contact_email']) ?>.</p>
- </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; ?>
- <?php if ((int) ($index + 1) === 3): ?>
- <button type="button" id="uploadNowBtn">Dateien jetzt speichern</button>
- <?php endif; ?>
- </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>
- <section id="statusSection" class="card hidden">
- <h2>Status</h2>
- <p id="statusMessage"></p>
- </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) ?>
- };
- </script>
- <script src="/assets/js/form.js"></script>
- </body>
- </html>
|