PHP Multiple Checkboxes
In this tutorial you will learn how to retrieve many values using the same checkbox name
- Getting multiple value using the same Check Box name.
For example when a form contains multiple checkboxes with the same name, multiple input an be retrieved using the following PHP code.
Sample PHP Code
<?php
$strExpert="";
if(isset($hidSubmit)){
$count=count($chkexpert);
for($i=0;$i<$count;$i++){$strExpert="$strExpert$chkexpert[$i], ";}
}
?>
Sample HTML Code for the above example
<form name="form1" method="post" action=""> <table width="100%" border="0" bgcolor="#D6E3F7">
<tr>
<td class="text">Your are Expertise field: </td>
</tr>
<tr>
<td class="examplelink">
<input type="checkbox" name="chkexpert[]" value="Java">
Java
<input type="checkbox" name="chkexpert[]" value="PHP">
PHP
<input type="checkbox" name="chkexpert[]" value="ASP">
ASP
<input type="checkbox" name="chkexpert[]" value=".NET">
.NET
<input type="checkbox" name="chkexpert[]" value="JavaScript">
JavaScript</td>
</tr>
<tr>
<td><input type="submit" name="Submit" value="Submit">
<input name="hidSubmit" type="hidden" id="hidSubmit2" value="true"></td>
</tr>
<tr>
<td class="subtitlesmall"><p>Result:</p>
<p><span class="reditalic">Your Expertise field: <?php echo $strExpert; ?></span></p></td>
</tr>
<tr>
<td class="reditalic"> </td>
</tr>
</table>
</form>