This is an extended question from: Get $_POST from multiple checkboxes
I am trying to get the labels of each checked checkbox, then display it as such:
"Sales | Engineering" (without the quotes)
Or if only one checkbox was selected:
"Sales"
HTML (myform.html):
<!DOCTYPE html>
<html>
<head></head>
<body>
<form name='myform' method='post' action='result.php'>
<label for='sales'>Sales</label>
<input type='checkbox' name='loc_chks[]' id='sales' value='Sales' /><br/>
<label for='insideSales'>Inside Sales</label>
<input type='checkbox' name='loc_chks[]' id='insideSales' value='Inside Sales' /><br/>
<label for='engineering'>Engineering</label>
<input type='checkbox' name='loc_chks[]' id='engineering' value='Engineering' /><br/>
<label for='fieldService'>Field Service</label>
<input type='checkbox' name='loc_chks[]' id='fieldService' value='Field Service' /><br/>
<label for='production'>Production</label>
<input type='checkbox' name='loc_chks[]' id='production' value='Production' /><br/>
<label for='warehouse'>Warehouse</label>
<input type='checkbox' name='loc_chks[]' id='warehouse' value='Warehouse'/><br/>
<br/>
<input type='submit' id='subBtn' value='Submit'/>
</form>
</body>
</html>
PHP (result.php):
<!DOCTYPE html>
<html>
<head></head>
<body>
<p><?php
if(!empty($_POST["loc_chks"]) and is_array($_POST["loc_chks"])) {
echo implode(' | ',$_POST["loc_chks"]);
} else { echo "we have a loser";}
?>
</p>
</body>
</html>
*Edited - the "if" statement in the php file always returns false even if multiple checkboxes are checked