Skip to content

Fix - Convert empty dropdown value (-1) to null on form submission#1196

Merged
Rom1-B merged 3 commits into
mainfrom
fix/empty-dropdown-null-on-form-submission
May 13, 2026
Merged

Fix - Convert empty dropdown value (-1) to null on form submission#1196
Rom1-B merged 3 commits into
mainfrom
fix/empty-dropdown-null-on-form-submission

Conversation

@RomainLvr
Copy link
Copy Markdown
Contributor

Checklist before requesting a review

Please delete options that are not relevant.

  • I have performed a self-review of my code.
  • I have added tests (when available) that prove my fix is effective or that my feature works.
  • I have updated the CHANGELOG with a short functional description of the fix or new feature.
  • This change requires a documentation update.

Description

  • It fixes !43956
  • Here is a brief description of what this PR does

When a form containing a Fields dropdown question (either via PluginFieldsQuestionType or the native QuestionTypeItemDropdown) is submitted without a value selected, GLPI sends -1 (or 0) as the items_id. This value was passed as-is to the INSERT query, but the underlying column is INT UNSIGNED, causing a MySQL "Out of range value" error and preventing ticket creation.

[2026-05-12 08:04:50] glpi.ERROR:   *** An error occured during the form `Test` submission: MySQL query error: Out of range value for column 'plugin_fields_dropdownfielddropdowns_id' at row 1 (1264) in SQL query "INSERT INTO `glpi_plugin_fields_tickettestblocs` (`plugin_fields_containers_id`, `plugin_fields_dropdownfielddropdowns_id`, `itemtype`, `items_id`, `entities_id`) VALUES ('2', '-1', 'Ticket', '8', '0')".
  Backtrace :
  ./src/DBmysql.php:416                              
  ./src/DBmysql.php:1377                             DBmysql->doQuery()
  ./src/CommonDBTM.php:778                           DBmysql->insert()
  ./src/CommonDBTM.php:1382                          CommonDBTM->addToDB()
  ./plugins/fields/inc/container.class.php:1430      CommonDBTM->add()
  ./plugins/fields/inc/container.class.php:1839      PluginFieldsContainer->updateFieldsValues()
  ./src/Plugin.php:1810                              PluginFieldsContainer::postItemAdd()
  ./src/CommonDBTM.php:1432                          Plugin::doHook()
  ...ation/AbstractCommonITILFormDestination.php:205 CommonDBTM->add()
  ./src/Session.php:2457                             Glpi\Form\Destination\AbstractCommonITILFormDestination->{closure:Glpi\Form\Destination\AbstractCommonITILFormDestination::createDestinationItems():205}()
  ...ation/AbstractCommonITILFormDestination.php:205 Session::callAsSystem()
  ...Glpi/Form/AnswersHandler/AnswersHandler.php:435 Glpi\Form\Destination\AbstractCommonITILFormDestination->createDestinationItems()
  ...Glpi/Form/AnswersHandler/AnswersHandler.php:288 Glpi\Form\AnswersHandler\AnswersHandler->createDestinations()
  ...Glpi/Form/AnswersHandler/AnswersHandler.php:206 Glpi\Form\AnswersHandler\AnswersHandler->doSaveAnswers()
  .../Controller/Form/SubmitAnswerController.php:156 Glpi\Form\AnswersHandler\AnswersHandler->saveAnswers()
  ...i/Controller/Form/SubmitAnswerController.php:83 Glpi\Controller\Form\SubmitAnswerController->saveSubmittedAnswers()
  ./vendor/symfony/http-kernel/HttpKernel.php:181    Glpi\Controller\Form\SubmitAnswerController->__invoke()
  ./vendor/symfony/http-kernel/HttpKernel.php:76     Symfony\Component\HttpKernel\HttpKernel->handleRaw()
  ./vendor/symfony/http-kernel/Kernel.php:208        Symfony\Component\HttpKernel\HttpKernel->handle()
  ./public/index.php:71                              Symfony\Component\HttpKernel\Kernel->handle()

Fix: In applyConfiguratedValueToInputUsingAnswers(), any items_id ≤ 0 is now converted to null before being added to the input, consistent with how GLPI core handles this (see EntityFieldStrategy).

@RomainLvr RomainLvr requested review from Rom1-B and stonebuzz May 12, 2026 08:16
@RomainLvr RomainLvr self-assigned this May 12, 2026
Comment thread inc/destinationfield.class.php Outdated
Co-authored-by: Romain B. <8530352+Rom1-B@users.noreply.github.com>
@RomainLvr RomainLvr requested a review from Rom1-B May 13, 2026 07:42
@Rom1-B Rom1-B merged commit 7edd5e8 into main May 13, 2026
3 checks passed
@Rom1-B Rom1-B deleted the fix/empty-dropdown-null-on-form-submission branch May 13, 2026 10:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants