I am a php newbie and i am trying to create a price range system for my ecommerce website project.
so I did a checkbox form:
Add javascript function submit() in onchange
<form method="POST" action="?">
<p><input type="checkbox" name="dori" value="dori" onchange="this.form.submit()"><em> 0 - 5000</em></p>
<p><input type="checkbox" name="bora" value="bora" onchange="this.form.submit()"><em> 5000 - 1000</em></p>
</form>
I implemented the submission of multiple checkbox value by using php as follows. It works perfectly for me and hope that it will work for everyone .
<?php
session_start();
$samsung=NULL;
if(!empty($_POST['samsung']))
$samsung = $_POST['samsung'];
$_SESSION["samsung"] = $samsung;
$samsung1 = $_SESSION["samsung"];
echo $samsung1."<br />";
$apple=NULL;
if(!empty($_POST['apple']))
$apple = $_POST['apple'];
$_SESSION["apple"] = $apple;
$apple1 = $_SESSION["apple"];
echo $apple1."<br />";
$low=NULL;
if(!empty($_POST['low']))
$low = $_POST['low'];
$_SESSION["low"] = $low;
$low1 = $_SESSION["low"];
echo $low1."<br />";
?>
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Checkbox</title>
</head>
<body>
<form action="checkbox.php" method="post">
Samsung<input type="checkbox" name="samsung" value="samsung" onchange="this.form.submit()" <?php if(!empty($_SESSION["samsung"])){echo "checked";} ?>>
Apple<input type="checkbox" name="apple" value="apple" onchange="this.form.submit()" <?php if(!empty($_SESSION["apple"])){echo "checked";} ?>>
5000-1000<input type="checkbox" name="low" value="low" onchange="this.form.submit()" <?php if(!empty($_SESSION["low"])){echo "checked";} ?>>
</form>
</body>
</html>
Here I use session variable so that once I checked Samsung it will persist even if I checked apple . Hope this example will help you.