Values submitted by a form with `multiple` in `bootstrap-select`

Willem Van Onsem picture Willem Van Onsem · Aug 12, 2014 · Viewed 12.6k times · Source

If one generates a form with bootstrap and bootstrap-select:

<form action="handle.php" method="post">
    <select name="pids" class="selectpicker" multiple>
        <option value="1">A</option>
        <option value="2">B</option>
        <option value="6">C</option>
    </select>
</form>

And one select all or multiple items, only the item with the last selected value is posted to the handle.php page.

handle.php

<?php
var_dump($_POST);
?>

result:

array(1) { ["pids"]=> string(1) "6" } 

how can one retrieve all selected items?

Answer

Dave O&#39;Dwyer picture Dave O'Dwyer · Aug 12, 2014

Its most likely a case that you need to set the name to pids[] (note the square brackets) The square brackets define an array instead of a single value.

<select name="pids[]" class="selectpicker" multiple>