Skip to content

Commit 9dd9777

Browse files
committed
fix(formanswer): catch and report exception to end user
1 parent 6ed85cd commit 9dd9777

File tree

1 file changed

+19
-4
lines changed

1 file changed

+19
-4
lines changed

inc/formanswer.class.php

+19-4
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
use Glpi\Application\View\TemplateRenderer;
3333
use Glpi\Toolbox\Sanitizer;
3434
use GlpiPlugin\Formcreator\Field\DropdownField;
35+
use Glpi\Application\ErrorHandler;
3536

3637
if (!defined('GLPI_ROOT')) {
3738
die("Sorry. You can't access this file directly");
@@ -800,7 +801,7 @@ function plugin_formcreator_checkComment(field) {
800801
* @return array the modified $input array
801802
*/
802803
public function prepareInputForAdd($input) {
803-
global $DB;
804+
global $DB, $GLPI;
804805

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

818-
if (!$this->validateFormAnswer($input)) {
819-
// Validation of answers failed
819+
try {
820+
if (!$this->validateFormAnswer($input)) {
821+
// Validation of answers failed
822+
return false;
823+
}
824+
} catch (Exception $e) {
825+
// A fatal error caught during validation of answers
826+
$GLPI->getErrorHandler()->handleException($e, false);
827+
Session::addMessageAfterRedirect(__('An internal error occured when verifying your answers. Please report it to your administrator.', 'formcreator'), false, ERROR);
820828
return false;
821829
}
822830
if (!$this->validateCaptcha($input)) {
@@ -828,7 +836,14 @@ public function prepareInputForAdd($input) {
828836
return false;
829837
}
830838

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

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

0 commit comments

Comments
 (0)