Php Dynamic Multiple choice button
<? Php
Function generate_checkboxes ($ name, $ options, $ default = array ()){
If (! Is_array ($ default )){
$ Default = array ();
}
Foreach ($ options as $ value => $ label ){
$ Html. = "<input type = checkbox ";
If (in_array ($ value, $ default )){
$ Html. = "checked ";
}
$ Html. = "name = \" {$ name} [] \ "value = \" $ value \ "> ";
$ Html. = $ label. "<br> ";
}
Return ($ html );
}
$ Options = array ("Music" => "Music ",
"Movie" => "movie ",
"Internet" => "Internet ",
"Tourism" => "Tourism ");
$ Interests = array ("Music" => "Music ",
"Internet" => "Internet"
);
$ Html = generate_checkboxes ("interests", $ options, $ interests );
?>
Select your hobbies:
<Form action = "" method = post>
<? Php echo $ html;?>
<Input type = submit value = "continue">
</Form>
<? Php
Foreach ($ _ REQUEST as $ k => $ v ){
Echo $ k; echo "--";
Echo $ v; echo "</br> ";
}
Echo "</br> ";
If (isset ($ _ POST ['interests']) {
Foreach ($ _ POST ['interests'] as $ k => $ v ){
Echo $ k; echo "--";
Echo $ v; echo "</br> ";
}
}
?>