Search code examples
formspostsemantic-uimultiple-value

SemanticUI Multiple select dont post multiple values


Im using Semantic UI for design and some functionalities and I failed to make multiple value posting in dropdown select - it adds blocks into the select input, but when submitting, posts only numeric string - one of the input values (instead of array). Seems to post the highest number from selection.

Can anyone tell me, how to make it working? (loading previous values works perfect);

<select class="ui dropdown" id="subjs" name="subj" multiple>
                <?php
                $selected = $cats->getsubj();
                $subs = $cats->getsubj(true);
                if (isset($subs) && count($subs) > 0)
                    for ($i = 0; $i < count($subs); $i++) {
                        $opt = (in_array($subs[$i], $selected)) ? ' selected="selected"' : '';
                        ?>
                        <option class="subjs" value="<?php echo $subs[$i]['ID']; ?>" <?php echo $opt; ?>><?php echo $subs[$i]['title']; ?></option>
                        <?php
                    }
                ?>
</select>

JS:

<script>
    $('.ui.dropdown').dropdown({
        maxSelections: 2
    });
</script>

PHP:

var_dump($_POST);

the script is listing of categories from database into select as options. Value for each option is it's ID (integer). One article may be liked with more than one category

All advices apreciated... Thanx


Solution

  • Well for all, who make stupid mistakes, simple add '[]' to the multiple select name parameter to post array.

    <select name="x[]"></select>