Fix market card save validation
This commit is contained in:
1 parent
6a12a43114
commit
28784ed6ac
1 file changed
+12
-2
@@ -33,6 +33,7 @@ if ($requestMethod === 'POST') {
|
|||||||
echo json_encode(['ok' => false, 'error' => 'Ungültige Anfrage']);
|
echo json_encode(['ok' => false, 'error' => 'Ungültige Anfrage']);
|
||||||
exit;
|
exit;
|
||||||
}
|
}
|
||||||
|
try {
|
||||||
$scope = (string) ($payload['scope'] ?? '');
|
$scope = (string) ($payload['scope'] ?? '');
|
||||||
$id = market_management_require_positive_id($payload['id'] ?? null, 'id');
|
$id = market_management_require_positive_id($payload['id'] ?? null, 'id');
|
||||||
$fields = is_array($payload['fields'] ?? null) ? $payload['fields'] : [];
|
$fields = is_array($payload['fields'] ?? null) ? $payload['fields'] : [];
|
||||||
@@ -61,13 +62,17 @@ if ($requestMethod === 'POST') {
|
|||||||
market_management_update_market($pdo, (int) ($existingOccurrence['market_definition_id'] ?? 0), $marketFields);
|
market_management_update_market($pdo, (int) ($existingOccurrence['market_definition_id'] ?? 0), $marketFields);
|
||||||
}
|
}
|
||||||
if ($contactFields !== []) {
|
if ($contactFields !== []) {
|
||||||
$contactId = (int) ($fields['contact_person_id'] ?? $existingOccurrence['contact_person_id'] ?? 0);
|
$submittedContactId = trim((string) ($fields['contact_person_id'] ?? ''));
|
||||||
|
$contactId = (int) ($submittedContactId !== '' ? $submittedContactId : ($existingOccurrence['contact_person_id'] ?? 0));
|
||||||
update_contact_details($pdo, $contactId, $contactFields);
|
update_contact_details($pdo, $contactId, $contactFields);
|
||||||
}
|
}
|
||||||
$organizerFields = [];
|
$organizerFields = [];
|
||||||
foreach (['organization_contact_id', 'contact_person_id'] as $organizerField) {
|
foreach (['organization_contact_id', 'contact_person_id'] as $organizerField) {
|
||||||
if (array_key_exists($organizerField, $fields)) {
|
if (array_key_exists($organizerField, $fields)) {
|
||||||
$organizerFields[$organizerField] = $fields[$organizerField];
|
$value = trim((string) $fields[$organizerField]);
|
||||||
|
if ($value !== '') {
|
||||||
|
$organizerFields[$organizerField] = $value;
|
||||||
|
}
|
||||||
unset($fields[$organizerField]);
|
unset($fields[$organizerField]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -87,6 +92,11 @@ if ($requestMethod === 'POST') {
|
|||||||
}
|
}
|
||||||
echo json_encode(['ok' => true]);
|
echo json_encode(['ok' => true]);
|
||||||
exit;
|
exit;
|
||||||
|
} catch (Throwable $error) {
|
||||||
|
http_response_code(422);
|
||||||
|
echo json_encode(['ok' => false, 'error' => $error->getMessage()], JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES);
|
||||||
|
exit;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$occurrenceId = filter_input(INPUT_GET, 'id', FILTER_VALIDATE_INT);
|
$occurrenceId = filter_input(INPUT_GET, 'id', FILTER_VALIDATE_INT);
|
||||||
|
|||||||
Reference in new issue
Block a user