Php Modx:FormIT Select字段在从MySQL表加载值时不会持久

Php Modx:FormIT Select字段在从MySQL表加载值时不会持久,php,mysql,modx,formit,Php,Mysql,Modx,Formit,我知道formItIsSelected实用程序在表单(例如)由于某种原因无法验证时可以很好地保持表单中选择字段的值。但是,当从MySQL中的表填充Select字段时,是否有人尝试过使用此选项?这肯定比用静态值填充的Select字段更有用 我在modx站点中有一个表单,与formit挂钩,其中有一个select字段,用于从MySQL中的表中动态检索值。当表单无法验证此特定字段时,将丢失用户选择的值。我的字段(在表单中)具有以下设置: <select id="Field245" name="t

我知道formItIsSelected实用程序在表单(例如)由于某种原因无法验证时可以很好地保持表单中选择字段的值。但是,当从MySQL中的表填充Select字段时,是否有人尝试过使用此选项?这肯定比用静态值填充的Select字段更有用

我在modx站点中有一个表单,与formit挂钩,其中有一个select字段,用于从MySQL中的表中动态检索值。当表单无法验证此特定字段时,将丢失用户选择的值。我的字段(在表单中)具有以下设置:

<select id="Field245" name="typeOfRelationship" class="field select medium" tabindex="4">[[!getRelationshipOptions? &selected=`[[!+fi.typeOfRelationship]]`]]</select>
[[!getRelationshipOptions?&selected=`[!+fi.typeOfRelationship]]`]
而代码段和正确工作的代码只需执行以下操作:

<?php if (!$modx->addPackage('contacts', MODX_CORE_PATH . 'components/contacts/model/')) {return 'Could not load xPDO model';}$current = $modx->getOption('selected', $scriptProperties, '');$output = [];$relationships= $modx->getCollection('RelationshipCodes');foreach ($relationships as $relationship) {$selected = $current == $relationship->get('codes') ? 'selected="selected' : '';$value=$relationship->get('descriptions');$output[] = '<option value="' . $relationship->get('descriptions') . '" ' . $selected . '>' . $relationship->get('descriptions') . '</option>';}return implode('', $output);

 $output[] = '<option value="' .$value . '" '. '[[!+fi.typeOfRelationship:FormItIsSelected=' ."'".$value. "'". $selected. ']]>' . $value . '</option>';