Formulare, WordPress-Import und E-Mail-Versand
Some checks failed
CI / PHP 8.3 / mariadb:10.6 (pull_request) Successful in 2m0s
CI / PHP 8.4 / mariadb:10.6 (pull_request) Successful in 2m7s
CI / PHP 8.3 / mariadb:11.4 (pull_request) Successful in 2m11s
CI / PHP 8.4 / mariadb:11.4 (pull_request) Successful in 2m7s
CI / PHP 8.3 / mysql:8.0 (pull_request) Failing after 2m52s
CI / PHP 8.4 / mysql:8.0 (pull_request) Failing after 3m2s
CI / PHP 8.3 / mysql:8.4 (pull_request) Failing after 2m31s
CI / PHP 8.4 / mysql:8.4 (pull_request) Failing after 2m27s
CI / Build-Artefakte aktuell (pull_request) Successful in 53s

- Formular-Plugin: Baukasten mit 13 Feldtypen, Bedingungen, Vorbelegung
  aus dem Profil, Datei-Uploads (geschützt), anonyme Formulare, „nur einmal“,
  Einsendeschluss, Sichtbarkeit, Löschfrist; Einsendungen im Backend und per
  Mail (optional ohne Angaben, Kopie an die Person); Rechte je Formular und
  Rolle für Ansehen/Export und Löschen; CSV für Excel; Pagebuilder-Block
- WordPress-Import (Plugin): WXR-Datei einlesen, Kategorien/Personen zuordnen,
  Beiträge mit Status, Datum, Beitragsbild und Bildern im Text übernehmen,
  optional Seiten mit Hierarchie; in Portionen, wiederholbar ohne Doppelungen
- E-Mail-Versand im Admin (SMTP, verschlüsseltes Passwort, Test-Mail)
- Speichertest unabhängig vom Verbrauch der Test-Suite

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This commit is contained in:
Friederich Loheide 2026-09-26 09:20:54 +00:00
parent f3987e8386
commit 11123fecc0
118 changed files with 4446 additions and 169 deletions

View file

@ -0,0 +1,21 @@
<script setup>
import { inject } from 'vue';
import FormRenderer from '../components/FormRenderer.vue';
defineProps({ block: { type: Object, required: true } });
const editing = inject('pagebuilder:editing', false);
</script>
<template>
<section v-if="block.props" class="rounded-lg border bg-card p-5 @3xl:p-8">
<template v-if="block.data.show_title">
<h3 class="text-xl font-semibold tracking-tight">{{ block.props.title }}</h3>
<p v-if="block.props.description" class="mt-2 mb-6 text-sm leading-relaxed whitespace-pre-line text-muted-foreground">{{ block.props.description }}</p>
</template>
<div :class="{ 'pointer-events-none opacity-80': editing }">
<FormRenderer :key="block.props.id" :form="block.props" />
</div>
</section>
<p v-else-if="editing" class="rounded-lg border border-dashed p-4 text-sm text-muted-foreground">Bitte rechts ein Formular auswählen.</p>
</template>

View file

@ -0,0 +1,199 @@
<script setup>
import { computed } from 'vue';
import { useForm, usePage } from '@inertiajs/vue3';
import { CircleCheck, EyeOff, LoaderCircle, Paperclip, Send, X } from '@lucide/vue';
import { Button } from '@/components/ui/button';
import { Input } from '@/components/ui/input';
import { Textarea } from '@/components/ui/textarea';
import NativeSelect from '@/components/NativeSelect.vue';
/**
* Stellt ein Formular dar (Formularseite und Pagebuilder-Block).
* Bedingungen werden hier für die Anzeige und auf dem Server für die Prüfung ausgewertet.
*/
const props = defineProps({
form: { type: Object, required: true },
compact: { type: Boolean, default: false },
});
const page = usePage();
const inputTypes = ['text', 'textarea', 'email', 'phone', 'number', 'date', 'select', 'radio', 'checkboxes', 'checkbox', 'file'];
function initial(field) {
const prefilled = props.form.prefill?.[field.key];
if (field.type === 'checkboxes' || field.type === 'file') return [];
if (field.type === 'checkbox') return false;
return prefilled ?? '';
}
const data = useForm({
answers: Object.fromEntries(props.form.fields.filter((f) => inputTypes.includes(f.type)).map((f) => [f.key, initial(f)])),
});
const submitted = computed(() => page.props.flash?.form_submitted === props.form.id);
function isVisible(field, depth = 0) {
if (!field.condition || depth > 10) return true;
const other = props.form.fields.find((f) => f.key === field.condition.field);
if (!other || !isVisible(other, depth + 1)) return false;
const raw = data.answers[field.condition.field];
const values = (Array.isArray(raw) ? raw : raw === true ? ['1'] : raw === false || raw === '' || raw == null ? [] : [String(raw)]).map(String);
const expected = field.condition.value ?? '';
switch (field.condition.operator) {
case 'not_equals': return !values.includes(expected);
case 'filled': return values.length > 0;
case 'empty': return values.length === 0;
default: return values.includes(expected);
}
}
const visibleFields = computed(() => props.form.fields.filter((field) => isVisible(field)));
function error(field) {
return data.errors[`answers.${field.key}`] ?? Object.entries(data.errors).find(([key]) => key.startsWith(`answers.${field.key}.`))?.[1];
}
function toggleOption(field, option) {
const values = new Set(data.answers[field.key]);
values.has(option) ? values.delete(option) : values.add(option);
data.answers[field.key] = [...values];
}
function addFiles(field, event) {
const files = [...(event.target.files ?? [])];
data.answers[field.key] = field.multiple ? [...data.answers[field.key], ...files].slice(0, 10) : files.slice(0, 1);
event.target.value = '';
}
function removeFile(field, index) {
data.answers[field.key] = data.answers[field.key].filter((_, i) => i !== index);
}
function submit() {
const visibleKeys = new Set(visibleFields.value.map((f) => f.key));
data.transform((values) => ({
answers: Object.fromEntries(Object.entries(values.answers).filter(([key]) => visibleKeys.has(key))),
})).post(props.form.url, {
forceFormData: true,
preserveScroll: true,
onSuccess: () => {
if (page.props.flash?.form_submitted === props.form.id) data.reset();
},
});
}
const formatSize = (bytes) => (bytes > 1024 * 1024 ? `${(bytes / 1024 / 1024).toFixed(1).replace('.', ',')} MB` : `${Math.max(1, Math.round(bytes / 1024))} KB`);
const fieldId = (field) => `f${props.form.id}-${field.key}`;
</script>
<template>
<div v-if="submitted" class="flex gap-3 rounded-lg border border-emerald-200 bg-emerald-50 p-5 text-emerald-950 dark:border-emerald-900 dark:bg-emerald-950/40 dark:text-emerald-100" role="status">
<CircleCheck class="mt-0.5 size-5 shrink-0 text-emerald-600" />
<div>
<p class="font-medium whitespace-pre-line">{{ form.confirmation }}</p>
<p v-if="form.send_copy" class="mt-1 text-sm opacity-80">Eine Kopie Ihrer Angaben ist per E-Mail unterwegs.</p>
</div>
</div>
<p v-else-if="form.already_submitted" class="rounded-lg border bg-muted px-5 py-4 text-sm">Sie haben dieses Formular bereits ausgefüllt. Vielen Dank!</p>
<p v-else-if="!form.open" class="rounded-lg border bg-muted px-5 py-4 text-sm">Dieses Formular nimmt keine Einsendungen mehr an.</p>
<form v-else class="grid gap-5 @xl:grid-cols-2" novalidate @submit.prevent="submit">
<p v-if="form.anonymous" class="flex items-start gap-2 rounded-md bg-muted px-3 py-2 text-[13px] text-muted-foreground @xl:col-span-2">
<EyeOff class="mt-0.5 size-4 shrink-0" /> Anonym: Ihr Name und Ihre E-Mail-Adresse werden nicht gespeichert.
</p>
<p v-if="data.errors.form" class="rounded-md bg-destructive/10 px-3 py-2 text-sm text-destructive @xl:col-span-2">{{ data.errors.form }}</p>
<template v-for="field in visibleFields" :key="field.key">
<h3 v-if="field.type === 'heading'" class="pt-2 text-lg font-semibold @xl:col-span-2">{{ field.text }}</h3>
<p v-else-if="field.type === 'paragraph'" class="text-sm leading-relaxed whitespace-pre-line text-muted-foreground @xl:col-span-2">{{ field.text }}</p>
<div v-else class="grid content-start gap-1.5" :class="field.width === 'half' ? '' : '@xl:col-span-2'">
<template v-if="field.type === 'checkbox'">
<label :for="fieldId(field)" class="flex items-start gap-2.5 text-sm">
<input :id="fieldId(field)" v-model="data.answers[field.key]" type="checkbox" class="mt-0.5 size-4 shrink-0 accent-[var(--brand)]" :aria-invalid="!!error(field)" />
<span>{{ field.label }}<span v-if="field.required" class="text-destructive"> *</span></span>
</label>
</template>
<template v-else>
<component :is="['radio', 'checkboxes'].includes(field.type) ? 'span' : 'label'" :for="fieldId(field)" class="text-[13px] font-medium" :id="`${fieldId(field)}-label`">
{{ field.label }}<span v-if="field.required" class="text-destructive"> *</span>
</component>
<Textarea v-if="field.type === 'textarea'" :id="fieldId(field)" v-model="data.answers[field.key]" :rows="field.rows ?? 4" :maxlength="field.max" :aria-invalid="!!error(field)" />
<NativeSelect v-else-if="field.type === 'select'" :id="fieldId(field)" v-model="data.answers[field.key]" :options="field.options.map((o) => ({ value: o, label: o }))" placeholder="Bitte wählen …" />
<div v-else-if="field.type === 'radio' || field.type === 'checkboxes'" class="grid gap-1.5" role="group" :aria-labelledby="`${fieldId(field)}-label`">
<label v-for="option in field.options" :key="option" class="flex items-center gap-2.5 text-sm">
<input
v-if="field.type === 'radio'"
v-model="data.answers[field.key]"
type="radio"
:name="fieldId(field)"
:value="option"
class="size-4 accent-[var(--brand)]"
/>
<input
v-else
type="checkbox"
:checked="data.answers[field.key].includes(option)"
class="size-4 accent-[var(--brand)]"
@change="toggleOption(field, option)"
/>
{{ option }}
</label>
</div>
<div v-else-if="field.type === 'file'" class="grid gap-2">
<ul v-if="data.answers[field.key].length" class="grid gap-1">
<li v-for="(file, index) in data.answers[field.key]" :key="index" class="flex items-center gap-2 rounded-md border bg-card px-3 py-1.5 text-sm">
<Paperclip class="size-4 shrink-0 text-muted-foreground" />
<span class="min-w-0 flex-1 truncate">{{ file.name }}</span>
<span class="text-xs text-muted-foreground">{{ formatSize(file.size) }}</span>
<button type="button" class="grid size-6 place-items-center rounded hover:bg-accent" :aria-label="`${file.name} entfernen`" @click="removeFile(field, index)"><X class="size-3.5" /></button>
</li>
</ul>
<label v-if="field.multiple || !data.answers[field.key].length" class="flex h-10 cursor-pointer items-center justify-center gap-2 rounded-md border border-dashed text-sm text-muted-foreground hover:border-brand-300 hover:text-foreground">
<Paperclip class="size-4" /> {{ field.multiple ? 'Dateien auswählen' : 'Datei auswählen' }}
<input :id="fieldId(field)" type="file" class="sr-only" :accept="field.accept" :multiple="field.multiple" @change="addFiles(field, $event)" />
</label>
</div>
<Input
v-else
:id="fieldId(field)"
v-model="data.answers[field.key]"
:type="{ email: 'email', phone: 'tel', number: 'number', date: 'date' }[field.type] ?? 'text'"
:placeholder="field.placeholder"
:maxlength="field.type === 'text' ? field.max : undefined"
:min="field.type === 'number' ? field.min : undefined"
:max="field.type === 'number' ? field.max : undefined"
:aria-invalid="!!error(field)"
/>
</template>
<p v-if="error(field)" class="text-[13px] text-destructive">{{ error(field) }}</p>
<p v-else-if="field.help" class="text-[13px] text-muted-foreground">
{{ field.help }}<template v-if="field.type === 'file' && field.max_size"> (höchstens {{ field.max_size }} MB)</template>
</p>
</div>
</template>
<div class="flex items-center gap-4 border-t pt-5 @xl:col-span-2">
<Button type="submit" :disabled="data.processing">
<LoaderCircle v-if="data.processing" class="animate-spin" />
<Send v-else />
{{ form.submit_label }}
</Button>
<span class="text-xs text-muted-foreground">* Pflichtfeld</span>
</div>
</form>
</template>

View file

@ -0,0 +1,33 @@
<script setup>
import { Link } from '@inertiajs/vue3';
import { ChevronRight, ClipboardList } from '@lucide/vue';
import EmptyState from '@/components/EmptyState.vue';
import AppLayout from '@/layouts/AppLayout.vue';
import { formatDate } from '@/lib/format';
defineProps({
forms: { type: Array, required: true },
});
</script>
<template>
<AppLayout title="Formulare">
<div class="mb-6">
<h1 class="text-2xl font-semibold tracking-tight">Formulare</h1>
<p class="mt-1 text-sm text-muted-foreground">Anträge, Anmeldungen und Meldungen – direkt online ausfüllen.</p>
</div>
<div v-if="forms.length" class="grid gap-4 md:grid-cols-2 xl:grid-cols-3">
<Link v-for="form in forms" :key="form.id" :href="form.url" class="group flex gap-4 rounded-lg border bg-card p-5 hover:border-brand-300">
<span class="grid size-10 shrink-0 place-items-center rounded-lg bg-brand-soft text-brand-text"><ClipboardList class="size-5" /></span>
<span class="min-w-0 flex-1">
<span class="block font-semibold group-hover:underline">{{ form.title }}</span>
<span v-if="form.description" class="mt-1 line-clamp-2 block text-sm text-muted-foreground">{{ form.description }}</span>
<span v-if="form.closes_at" class="mt-2 block text-xs text-muted-foreground">Bis {{ formatDate(form.closes_at) }}</span>
</span>
<ChevronRight class="mt-2.5 size-4 shrink-0 text-muted-foreground" />
</Link>
</div>
<div v-else class="rounded-lg border bg-card"><EmptyState :icon="ClipboardList" title="Keine Formulare" text="Derzeit sind keine Formulare für Sie freigegeben." /></div>
</AppLayout>
</template>

View file

@ -0,0 +1,29 @@
<script setup>
import { Link } from '@inertiajs/vue3';
import { ArrowLeft, CalendarClock } from '@lucide/vue';
import AppLayout from '@/layouts/AppLayout.vue';
import { formatDate } from '@/lib/format';
import FormRenderer from '../components/FormRenderer.vue';
defineProps({
form: { type: Object, required: true },
});
</script>
<template>
<AppLayout :title="form.title">
<div class="mx-auto max-w-3xl">
<Link href="/formulare" class="mb-6 inline-flex items-center gap-1.5 text-sm font-medium text-muted-foreground hover:text-foreground">
<ArrowLeft class="size-4" /> Alle Formulare
</Link>
<h1 class="text-3xl font-semibold tracking-tight">{{ form.title }}</h1>
<p v-if="form.description" class="mt-3 leading-relaxed whitespace-pre-line text-muted-foreground">{{ form.description }}</p>
<p v-if="form.closes_at && form.open" class="mt-3 inline-flex items-center gap-1.5 text-[13px] text-muted-foreground">
<CalendarClock class="size-4" /> Einsendeschluss: {{ formatDate(form.closes_at) }}
</p>
<div class="@container mt-8 rounded-lg border bg-card p-5 sm:p-8">
<FormRenderer :form="form" />
</div>
</div>
</AppLayout>
</template>

View file

@ -0,0 +1,6 @@
<x-filament-panels::page>
@if ($this->record->isAnonymous())
<p class="text-sm text-gray-500">Anonymes Formular – Namen werden nicht gespeichert.</p>
@endif
{{ $this->table }}
</x-filament-panels::page>

View file

@ -0,0 +1,37 @@
<!doctype html>
<html lang="de">
<head><meta charset="utf-8"><meta name="viewport" content="width=device-width"></head>
<body style="margin:0;background:#f4f5f7;font-family:-apple-system,Segoe UI,Roboto,Helvetica,Arial,sans-serif;color:#1a1d21">
<div style="max-width:640px;margin:0 auto;padding:24px">
<p style="margin:0 0 16px;font-size:13px;color:#5f6670">{{ $portalName }}</p>
<div style="background:#fff;border:1px solid #e3e5e8;border-radius:8px;padding:24px">
<h1 style="margin:0 0 4px;font-size:20px">{{ $form->title }}</h1>
<p style="margin:0 0 20px;font-size:14px;color:#5f6670">
@if ($copy)
Vielen Dank! Hier eine Kopie Ihrer Angaben vom {{ $submission->created_at->timezone(config('app.timezone'))->format('d.m.Y, H:i') }} Uhr.
@else
Eingegangen am {{ $submission->created_at->timezone(config('app.timezone'))->format('d.m.Y, H:i') }} Uhr
– {{ $person ? 'von '.$person->name.' ('.$person->email.')' : 'anonym' }}.
@endif
</p>
@if ($answers !== null)
<table style="width:100%;border-collapse:collapse;font-size:14px">
@foreach ($answers as $answer)
<tr>
<td style="padding:8px 12px 8px 0;border-top:1px solid #e3e5e8;vertical-align:top;color:#5f6670;width:40%">{{ $answer['label'] }}</td>
<td style="padding:8px 0;border-top:1px solid #e3e5e8;vertical-align:top;white-space:pre-line">{{ $answer['value'] !== '' ? $answer['value'] : '–' }}</td>
</tr>
@endforeach
</table>
@else
<p style="font-size:14px">Die Angaben sind aus Datenschutzgründen nicht in dieser E-Mail enthalten.</p>
@endif
@if ($resultsUrl)
<p style="margin:24px 0 0"><a href="{{ $resultsUrl }}" style="display:inline-block;background:#1a1d21;color:#fff;text-decoration:none;padding:10px 16px;border-radius:6px;font-size:14px">Ergebnisse im Portal öffnen</a></p>
@endif
</div>
</div>
</body>
</html>