GLPI Version
11.0.7
Plugin version
1.24.0
Bug description
When a ticket is created from a Helpdesk form (GLPI 11 forms), the value of a PluginFieldsQuestionType answer linked to a simple field (number, text, textarea, richtext, url, date, datetime) can be silently overwritten by the items_id of a previously processed QuestionTypeItemDropdown answer.
Examples observed in production on a custom number field "contact phone":
| User typed |
Stored value |
Cause |
3800 |
18 |
An earlier item-dropdown answer in the form had items_id = 18 |
3632 |
1 |
An earlier item-dropdown answer in the form had items_id = 1 |
Relevant log output
No PHP error / log output. The value is silently corrupted on save.
Page URL
No response
Steps To reproduce
- Create a Helpdesk form whose destination is
Ticket.
- Add at least one question of type GLPI item (rendered as
QuestionTypeItemDropdown, e.g. Location, Category…).
- Add a "Field" question (
PluginFieldsQuestionType) linked to a custom field of type number (or any non-dropdown, non-glpi_item type).
- As an end user, submit the form: pick any item in the GLPI item question, and type any value (e.g.
3800) in the number field.
- Open the resulting ticket and look at the stored value of the custom field.
Expected: the field stores 3800 (the value typed by the user).
Actual: the field stores the items_id of the item selected in the GLPI item question.
Your GLPI setup information
No response
Anything else?
Root cause
In inc/destinationfield.class.php, PluginFieldsDestinationField::applyConfiguratedValueToInputUsingAnswers() iterates over the form answers. Inside the loop, $value is assigned only in the QuestionTypeItemDropdown branch:
foreach ($answers as $answer) {
...
if ($question->getQuestionType() instanceof QuestionTypeItemDropdown) {
...
$value = $answer->getRawAnswer()['items_id']; // set here
} else {
$field_id = (new PluginFieldsQuestionType())->getDefaultValueFieldId($question);
$field = PluginFieldsField::getById($field_id);
// $value is NOT reset
}
...
} else {
$input[$field_name] = $value ?? $answer->getRawAnswer(); // leaks across iterations
}
}
$value is never reset between iterations, so on a later PluginFieldsQuestionType iteration whose target field type falls into the final else branch (number, text, textarea, richtext, url, date, datetime), the expression $value ?? $answer->getRawAnswer() returns the stale $value from the previous iteration instead of the user's actual answer.
Suggested fix (and applied to my local version)
$value only has meaning in the QuestionTypeItemDropdown branch, and even there it is not consumed by the glpi_item / dropdown branches (which use $answer->getRawAnswer()['items_id'] directly). For the fall-through else, the value should always come from the current answer:
- $input[$field_name] = $value ?? $answer->getRawAnswer();
+ $input[$field_name] = $answer->getRawAnswer();
Alternatively, reset $value = null; at the top of the foreach. Either patch removes the cross-iteration leak.
GLPI Version
11.0.7
Plugin version
1.24.0
Bug description
When a ticket is created from a Helpdesk form (GLPI 11 forms), the value of a
PluginFieldsQuestionTypeanswer linked to a simple field (number,text,textarea,richtext,url,date,datetime) can be silently overwritten by theitems_idof a previously processedQuestionTypeItemDropdownanswer.Examples observed in production on a custom
numberfield "contact phone":380018items_id = 1836321items_id = 1Relevant log output
Page URL
No response
Steps To reproduce
Ticket.QuestionTypeItemDropdown, e.g. Location, Category…).PluginFieldsQuestionType) linked to a custom field of typenumber(or any non-dropdown, non-glpi_itemtype).3800) in the number field.Expected: the field stores
3800(the value typed by the user).Actual: the field stores the
items_idof the item selected in the GLPI item question.Your GLPI setup information
No response
Anything else?
Root cause
In
inc/destinationfield.class.php,PluginFieldsDestinationField::applyConfiguratedValueToInputUsingAnswers()iterates over the form answers. Inside the loop,$valueis assigned only in theQuestionTypeItemDropdownbranch:$valueis never reset between iterations, so on a laterPluginFieldsQuestionTypeiteration whose target field type falls into the finalelsebranch (number,text,textarea,richtext,url,date,datetime), the expression$value ?? $answer->getRawAnswer()returns the stale$valuefrom the previous iteration instead of the user's actual answer.Suggested fix (and applied to my local version)
$valueonly has meaning in theQuestionTypeItemDropdownbranch, and even there it is not consumed by theglpi_item/dropdownbranches (which use$answer->getRawAnswer()['items_id']directly). For the fall-throughelse, the value should always come from the current answer:Alternatively, reset
$value = null;at the top of theforeach. Either patch removes the cross-iteration leak.