Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 13 additions & 3 deletions js/modules/Forms/RendererController.js
Original file line number Diff line number Diff line change
Expand Up @@ -307,9 +307,19 @@ export class GlpiFormRendererController

} catch (e) {
console.error(e);
glpi_toast_error(
__("Failed to submit form, please contact your administrator.")
);

// Always display the default error message
let errorMessage = __("Failed to submit form, please contact your administrator.");

// Try to extract and concatenate specific error messages from the response
if (e.responseJSON && e.responseJSON.errors && e.responseJSON.errors.length > 0) {
const specificErrors = e.responseJSON.errors
.map(msg => _.escape(msg))
.join("<br>");
errorMessage = `${errorMessage}<br><br><strong>${__("Details:")}</strong><br>${specificErrors}`;
}

glpi_toast_error(errorMessage);
} finally {
this.#enableActions();
submit.removeClass('btn-loading');
Expand Down
28 changes: 20 additions & 8 deletions src/Glpi/Controller/Form/SubmitAnswerController.php
Original file line number Diff line number Diff line change
Expand Up @@ -76,16 +76,28 @@ public function __invoke(Request $request): Response
$form = $this->loadSubmittedForm($request);
$this->checkFormAccessPolicies($form, $request);

$answers = $this->saveSubmittedAnswers($form, $request);
$links = $answers->getLinksToCreatedItems();
try {
$answers = $this->saveSubmittedAnswers($form, $request);
$links = $answers->getLinksToCreatedItems();

if ($is_unauthenticated_user) {
AltchaManager::getInstance()->removeChallenge($altcha);
}
if ($is_unauthenticated_user) {
AltchaManager::getInstance()->removeChallenge($altcha);
}

return new JsonResponse([
'links_to_created_items' => $links,
]);
return new JsonResponse([
'links_to_created_items' => $links,
]);
} catch (\Throwable $th) {
$messages = [];
if (isset($_SESSION['MESSAGE_AFTER_REDIRECT'][ERROR])) {
$messages = $_SESSION['MESSAGE_AFTER_REDIRECT'][ERROR];
unset($_SESSION['MESSAGE_AFTER_REDIRECT'][ERROR]);
}

return new JsonResponse([
'errors' => $messages,
], Response::HTTP_INTERNAL_SERVER_ERROR);
}
}

private function loadSubmittedForm(Request $request): Form
Expand Down
Loading