1

formItIsSelected ユーティリティは、(たとえば) 何らかの理由でフォームの検証に失敗した場合に、フォーム内の Select フィールドの値を保持するために完全に機能することを知っています。しかし、MySQL のテーブルから Select フィールドに入力するときに、これを使用しようとした人はいますか? これは、静的な値が入力された Select フィールドよりも確実に便利です..

modxサイトにフォームがあり、フォームにフックされ、その中の選択フィールドがMySQLのテーブルから動的に値を取得します。フォームがこの特定のフィールドの検証に失敗すると、ユーザーが選択した値が失われます。私のフィールド(フォーム内)には次の設定があります:

<select id="Field245" name="typeOfRelationship" class="field select medium" tabindex="4">[[!getRelationshipOptions? &selected=`[[!+fi.typeOfRelationship]]`]]</select>

スニペットと which は正しく機能します。単純に次のことを行います。

<?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[] 行を次のように置き換えると:

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

これは失敗します!エラーは発生しませんが、フォームが検証に失敗したときに Select フィールドの設定が失われることはあります。問題がありますか?それとも、FormItIsSelected はそのコンテキストでは機能しないのでしょうか?

大変感謝します

4

0 に答える 0