Skip to content

Commit 599451a

Browse files
committed
fix(formanswer): redirect after submit may lead to unavailable page
1 parent 7b9e941 commit 599451a

File tree

1 file changed

+15
-14
lines changed

1 file changed

+15
-14
lines changed

ajax/formanswer.php

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -88,28 +88,29 @@
8888
}
8989

9090
// redirect to created item
91-
if ($_SESSION['glpibackcreated'] && Ticket::canView()) {
92-
if (strpos($_SERVER['HTTP_REFERER'], 'form.form.php') === false) {
93-
// User was not testing the form from preview
94-
if (count($formAnswer->targetList) == 1) {
95-
$target = current($formAnswer->targetList);
96-
echo json_encode(
97-
[
98-
'redirect' => $target->getFormURLWithID($target->getID()),
99-
], JSON_FORCE_OBJECT
100-
);
101-
die();
102-
}
91+
if ($_SESSION['glpibackcreated']) {
92+
if (strpos($_SERVER['HTTP_REFERER'], 'form.form.php') !== false) {
10393
echo json_encode(
10494
[
105-
'redirect' => $formAnswer->getFormURLWithID($formAnswer->getID()),
95+
'redirect' => (new PluginFormcreatorForm())->getFormURLWithID($formAnswer->fields['plugin_formcreator_forms_id']),
96+
], JSON_FORCE_OBJECT
97+
);
98+
die();
99+
}
100+
// User was not testing the form from preview
101+
reset($formAnswer->targetList);
102+
$target = current($formAnswer->targetList);
103+
if (count($formAnswer->targetList) == 1 && $target::canView()) {
104+
echo json_encode(
105+
[
106+
'redirect' => $target->getFormURLWithID($target->getID()),
106107
], JSON_FORCE_OBJECT
107108
);
108109
die();
109110
}
110111
echo json_encode(
111112
[
112-
'redirect' => (new PluginFormcreatorForm())->getFormURLWithID($formAnswer->fields['plugin_formcreator_forms_id']),
113+
'redirect' => $formAnswer->getFormURLWithID($formAnswer->getID()),
113114
], JSON_FORCE_OBJECT
114115
);
115116
die();

0 commit comments

Comments
 (0)