We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 42161
    • 42 Posts
    There is a select in a FormIt form and I want its options to be populated by a snippet.
    [[!populateSelectOptions]]
    
    <select name='builderID'>
        [[!+builder_options]]
    </select>
    // snippet populateSelectOptions
    $selectedBuilderID = $_SESSION['selectedBuilderID'];
    
    foreach ($builders as $builder){
    	$selected = (isset($selectedBuilderID) && $builder->get('id') == selectedBuilderID) ? ' selected' : '';
    	$ph_builder .= '<option value="' . $builder->get('id') . '[[!+builderID:is=`' . $builder->get('id') . '`
    :then=` selected`]]"' . $selected . '>' . $builder->get('name') . '</option>';
    }
    $modx->setPlaceholder('builder_options', $ph_builder);

    I tried to call the snippet as a FormIt preHook, as a snippet inside the <select> tag, but result is the same - options are loaded, the correct option is selected, but if I empty a required field in the form and submit it, the <select> resets to the first option, as if fi.placeholders were not there.