PHP Multiple Select Dropdown Example

Admin   PHP   112  2021-03-18 07:50:04

Hi Guys

Today,I will learn you how to create multiple select dropdown in php. We will show example of php multiple select dropdown.In this example I will create multiple select dropdown using bootstrap in php.you can easily create Multiple Select Dropdown in php.we will make Multiple Select Dropdown using php

Here, I will give you full example for php multiple select dropdown as bellow.

Example

../index.php

 

<html lang="en">

<head>

<meta charset="utf-8">

<title>Multiple Select Dropdown in PHP</title>

<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">

<link rel="preconnect" href="https://fonts.gstatic.com">

<link href="https://fonts.googleapis.com/css2?family=JetBrains+Mono:[email protected]&display=swap" rel="stylesheet">

<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css">

<style>

body{

font-family: 'JetBrains Mono', monospace;

background:#d2d2d2;

}

.error{

color:red;

}

select{

width: 100%;

min-height:150px;

}

.main-box{

border-radius:5px;

background:#fff;

padding:15px;

border:1px solid #48161D;

box-shadow:2px 2px 5px #d2d2d2;

}

.select-tag{

background:#48161D;

color:#fff;

border-radius:15px;

display: inline-block;

font-size:14px;

padding:3px 15px;

margin-left:5px;

}

</style>

</head>

<body>

<div class="container mt-5 pt-5">

<div class="row">

<div class="col-md-6 main-box offset-md-3">

<form action="" method="post" class="mb-3">

<div class="row">

<div class="col-md-12 text-center title mb-2">

<h4>Multiple Select Dropdown in PHP</h4>

</div>

<div class="col-md-12">

<select name="lang[]" multiple class="form-control">

<option value="" disabled selected>Choose option</option>

<option value="Laravel">Laravel</option>

<option value="Php">Php</option>

<option value="Jquery">Jquery</option>

<option value="Node Js">NodeJs</option>

<option value="Bootstrap">Bootstrap</option>

</select>

</div>

<div class="col-md-12 text-center mt-4">

<input type="submit" name="submit" vlaue="Choose options" class="btn btn-success btn-sm">

</div>

<div class="col-md-12 text-center mt-2">

<?php

if(isset($_POST['submit'])){

if(!empty($_POST['lang'])) {

foreach($_POST['lang'] as $selected){

echo '<p class="select-tag mt-3">'.$selected.'</p>';

}

}else{

echo '<p class="error alert alert-danger mt-3">Please select any value</p>';

}

}

?>

</div>

</div>

</form>

</div>

</div>

</div>

</body>

</html>

It will help you ....