select2 multiple in php
// In your HTML:
<form method="post">
<select class="select2" name="listbox[]" multiple="multiple">
<option value="One">One</option>
<option value="Two">Two</option>
<option value="Three">Three</option>
<option value="Four">Four</option>
</select>
<input type="submit" name="btn" value="Get the Records">
</form>
// In your Javascript (external .js resource or <script> tag):
$(document).ready(function() {
$('.select2').select2();
});
// In your PHP
<?php
if (isset($_POST['btn']) && $_SERVER['REQUET_METHOD']==="POST") {
$items = $_POST['listbox'];
foreach ($items as $item) {
// Run SQL Query or do any other action
echo $item.'<br>';
}
}
?>