We can design and create our Form using HTML code and using PHP code we can access the values of selected checkboxes and can use them to save to database or any other process on the server.
Let's create our form first. You can use the below code example to create your form that will have checkbox type controls.
<form action="save_brand.php" method="post">
TATA<input type="checkbox" name="car_brand[]" value="tata">
Hyundai<input type="checkbox" name="car_brand[]" value="hyundai">
Volvo<input type="checkbox" name="car_brand[]" value="volvo">
Tesla<input type="checkbox" name="car_brand[]" value="tesla">
<input type="submit" value="submit">
</form>
The PHP code that will run after submitting the form and getting the values of selected checkboxes is as below.
save_brand.php
<?php
$car_brands = $_POST['car_brand'];
foreach ($car_brands as $brand){
echo $brand;
}
?>
0 Comments