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) {