<select name="workregion_01"> <option value="" [[!+reg.workregion_01=``]]>Region 01 - Please select...</option> <option value="SouthWest" [[!+reg.workregion_01:is=`SouthWest`:then=`selected`]]>SouthWest</option> <option value="London" [[!+reg.workregion_01:is=`London`:then=`selected`]]>London</option> <option value="Wales" [[!+reg.workregion_01:is=`Wales`:then=`selected`]]>Wales</option> <option value="Scotland" [[!+reg.workregion_01:is=`Scotland`:then=`selected`]]>Scotland</option> </select>
This question has been answered by dubbs. See the first response.
Just thinking out loud here...
If you haven't already, store these values in a table. You could then use two migxloopcollections to get first the default value from your user table and then get all the rest except the default from the workregion table. The tpls for each collection would be the same and would build your option list.
<select name="workregion_01"> <option value="" [[+workregion=``]]>Region 01 - Please select...</option> <option value="SouthWest" [[+workregion:is=`SouthWest`:then=`selected`]]>SouthWest</option> <option value="London" [[+workregion:is=`London`:then=`selected`]]>London</option> <option value="Wales" [[+workregion:is=`Wales`:then=`selected`]]>Wales</option> <option value="Scotland" [[+workregion:is=`Scotland`:then=`selected`]]>Scotland</option> </select>
$current_id = $modx->user->get('id'); $sql = "SELECT userworkregion as workregion from user_ext_table WHERE user_id = $current_id"; $sql .= "UNION SELECT workregion as workregion from workregion_table"; $sql .= "WHERE workregion NOT IN (SELECT userworkregion from user_ext_table WHERE user_id = $current_id)"; foreach ($modx->query($sql) as $row) { $output = $modx->getChunk('displayWRChunk',array( 'wregion' => $row, )); } return $output;
<option value="[[+wregion]]" [[!+reg.workregion_01:is=`[[+wregion]]`:then=`selected`]]>[[+wregion]]</option>
<option value="[[+wregion]]" [[+reg.workregion_01_selected]]"</option>
/* If workregion_01 is set */ $modx->setPlaceholder('reg.workregion_01_selected', 'selected="selected"'); /* else */ $modx->setPlaceholder('reg.workregion_01_selected', '');
You may have a parsing order issue where the reg.workregion.. placeholders are not set at the time the conditional is parsed. First, try removing the ! from the placeholder tag. That ! delays the processing of the tag, possibly until it's to late.
I usually use a snippet and do it this way. It avoids the use of conditional output modifiers so it's faster and more reliable.
<option value="[[+wregion]]" [[+reg.workregion_01_selected]]"<="" option="">
Then in the snippet:
/* If workregion_01 is set */ $modx->setPlaceholder('reg.workregion_01_selected', 'selected="selected"'); /* else */ $modx->setPlaceholder('reg.workregion_01_selected', '');
</option>
<option value="SouthWest" [[+workregion_01:is=`SouthWest`:then=`selected`]]>SouthWest</option>