Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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?

like image 428
Willem Van Onsem Avatar asked Aug 12 '14 14:08

Willem Van Onsem


1 Answers

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>
like image 129
Dave O'Dwyer Avatar answered Oct 03 '22 06:10

Dave O'Dwyer