Lettersail: online English school for kids on MODX 3 (templates, chunks, snippets, plugins, scripts)
This commit is contained in:
commit
3799cf8de5
96 files changed
+4423
No files matched your search
@@ -0,0 +1,28 @@
|
||||
<?php
|
||||
$errors = [];
|
||||
foreach (['name', 'phone', 'age', 'consent', 'guard', 'save'] as $field) {
|
||||
$message = trim(strip_tags((string) $modx->getPlaceholder('fi.error.' . $field)));
|
||||
if ($message !== '') {
|
||||
$errors[$field] = $message;
|
||||
}
|
||||
}
|
||||
$success = (string) $modx->getPlaceholder('fi.success') === '1' && $errors === [];
|
||||
$general = (string) $modx->getPlaceholder('fi.validation_error_message');
|
||||
|
||||
$body = ['ok' => $success];
|
||||
if (!$success) {
|
||||
$field = array_key_first($errors) ?? '';
|
||||
$body['field'] = in_array($field, ['name', 'phone', 'age', 'consent'], true) ? $field : '';
|
||||
$body['message'] = $field === 'guard' ? $modx->lexicon('ls_err_guard_retry') : ($errors[$field] ?? $modx->lexicon('ls_err_save'));
|
||||
$body['code'] = $field === 'guard' ? ($errors['guard'] ?? 'guard') : '';
|
||||
}
|
||||
|
||||
while (ob_get_level()) {
|
||||
ob_end_clean();
|
||||
}
|
||||
http_response_code($success ? 200 : 422);
|
||||
header('Content-Type: application/json; charset=utf-8');
|
||||
header('Cache-Control: no-store');
|
||||
header('X-Robots-Tag: noindex');
|
||||
echo json_encode($body, JSON_UNESCAPED_UNICODE);
|
||||
exit;
|
||||
Reference in new issue
Block a user