how to handle dynamic multiple checkbox in php

<?php

if($_SERVER[‘REQUEST_METHOD’]==’POST’)
{
$str=””;
// if the chkbox selected then selected checkbox values are come otherwise its not come
foreach($_POST[‘chkbox’] as  $chkbox)
{
$str .=$chkbox.”,”;
}
echo $str;
echo substr($str,0,-1);//remove last one char (, comma) from this string
}

?>
<!– suppose you have dynamic checkbox. Those comes from database  . So, you can use loop but in this small example We used static. –>
<form action=”” method=”post”>
Name : <input type=”text” name=”nm” >
Check Box : <input type=”checkbox” name=”chkbox[]” value=”1″ > FootBall
<input type=”checkbox” name=”chkbox[]” value=”9″ > Cricket
<input type=”checkbox” name=”chkbox[]”  value=”3″> VollyBall
<input type=”checkbox” name=”chkbox[]”  value=”5″> Tennis
<input type=”submit” value=”Save”>

</form>


Comments

One response to “how to handle dynamic multiple checkbox in php”

  1. […] RSS ← how to handle dynamic multiple checkbox in php […]

Leave a Reply

Your email address will not be published. Required fields are marked *