Skip to content

Commit 8ff7ff9

Browse files
committed
fix(formanswer): PHP 8.1 compatbility, error message if invalid JSON detected
1 parent abed861 commit 8ff7ff9

File tree

3 files changed

+10
-3
lines changed

3 files changed

+10
-3
lines changed

inc/targetproblem.class.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,7 @@ public function save(PluginFormcreatorFormAnswer $formanswer): ?CommonDBTM {
186186
];
187187
foreach ($problemFields as $problemFields) {
188188
$data[$problemFields] = $this->prepareTemplate(
189-
$this->fields[$problemFields],
189+
$this->fields[$problemFields] ?? '',
190190
$formanswer,
191191
$problemFields == 'content' // only content supports rich text
192192
);

inc/targetticket.class.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -825,7 +825,7 @@ public function save(PluginFormcreatorFormAnswer $formanswer): ?CommonDBTM {
825825
$data['date'] = $_SESSION['glpi_currenttime'];
826826

827827
$data['content'] = $this->prepareTemplate(
828-
$this->fields['content'],
828+
$this->fields['content'] ?? '',
829829
$formanswer,
830830
$richText
831831
);

js/scripts.js

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1392,7 +1392,14 @@ var plugin_formcreator = new function() {
13921392
window.location = data.redirect;
13931393
}
13941394
}).fail(function (xhr, data) {
1395-
if (xhr.responseText == '' || typeof(xhr.responseJSON.message) == 'undefined') {
1395+
if (xhr.responseText == '') {
1396+
displayAjaxMessageAfterRedirect();
1397+
return;
1398+
}
1399+
if (typeof(xhr.responseJSON) == 'undefined') {
1400+
alert(i18n.textdomain('formcreator').__('An internal error occurred. Please report it to administrator.', 'formcreator'));
1401+
}
1402+
if (typeof(xhr.responseJSON.message) == 'undefined') {
13961403
displayAjaxMessageAfterRedirect();
13971404
return;
13981405
}

0 commit comments

Comments
 (0)