From 2862d7a6e9fbebe99895f68802b0afd44c465ec4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mathias=20Gla=CC=88ser?= Date: Sat, 19 Sep 2026 14:28:02 +0200 Subject: [PATCH] Allow saving without contact details --- public/api/market-occurrence.php | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/public/api/market-occurrence.php b/public/api/market-occurrence.php index 0a29c63..8fc0bd5 100644 --- a/public/api/market-occurrence.php +++ b/public/api/market-occurrence.php @@ -64,7 +64,12 @@ if ($requestMethod === 'POST') { if ($contactFields !== []) { $submittedContactId = trim((string) ($fields['contact_person_id'] ?? '')); $contactId = (int) ($submittedContactId !== '' ? $submittedContactId : ($existingOccurrence['contact_person_id'] ?? 0)); - update_contact_details($pdo, $contactId, $contactFields); + $hasContactValue = array_reduce($contactFields, static fn (bool $carry, mixed $value): bool => $carry || trim((string) $value) !== '', false); + if ($contactId > 0 && ($hasContactValue || $submittedContactId !== '')) { + update_contact_details($pdo, $contactId, $contactFields); + } elseif ($hasContactValue) { + throw new InvalidArgumentException('Für E-Mail oder Telefon muss eine Kontaktperson ausgewählt sein.'); + } } $organizerFields = []; foreach (['organization_contact_id', 'contact_person_id'] as $organizerField) {