Skip to content

Commit

Permalink
fix(formanswer): catch and report exception to end user
Browse files Browse the repository at this point in the history
  • Loading branch information
btry committed Apr 12, 2023
1 parent 6ed85cd commit 9dd9777
Showing 1 changed file with 19 additions and 4 deletions.
23 changes: 19 additions & 4 deletions inc/formanswer.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
use Glpi\Application\View\TemplateRenderer;
use Glpi\Toolbox\Sanitizer;
use GlpiPlugin\Formcreator\Field\DropdownField;
use Glpi\Application\ErrorHandler;

if (!defined('GLPI_ROOT')) {
die("Sorry. You can't access this file directly");
Expand Down Expand Up @@ -800,7 +801,7 @@ function plugin_formcreator_checkComment(field) {
* @return array the modified $input array
*/
public function prepareInputForAdd($input) {
global $DB;
global $DB, $GLPI;

// A requester submits his answers to a form
if (!isset($input['plugin_formcreator_forms_id'])) {
Expand All @@ -815,8 +816,15 @@ public function prepareInputForAdd($input) {
}
}

if (!$this->validateFormAnswer($input)) {
// Validation of answers failed
try {
if (!$this->validateFormAnswer($input)) {
// Validation of answers failed
return false;
}
} catch (Exception $e) {
// A fatal error caught during validation of answers
$GLPI->getErrorHandler()->handleException($e, false);
Session::addMessageAfterRedirect(__('An internal error occured when verifying your answers. Please report it to your administrator.', 'formcreator'), false, ERROR);
return false;
}
if (!$this->validateCaptcha($input)) {
Expand All @@ -828,7 +836,14 @@ public function prepareInputForAdd($input) {
return false;
}

$input['name'] = $DB->escape($this->parseTags($form->fields['formanswer_name']));
try {
$input['name'] = $DB->escape($this->parseTags($form->fields['formanswer_name']));
} catch (Exception $e) {
// A fatal error caught during parsing of tags
$GLPI->getErrorHandler()->handleException($e, false);
Session::addMessageAfterRedirect(__('An internal error occured when verifying your answers. Please report it to your administrator.', 'formcreator'), false, ERROR);
return false;
}

$input = $this->setValidator($input, $form);

Expand Down

0 comments on commit 9dd9777

Please sign in to comment.