Jump to content

checkbox


jaymc

Recommended Posts

Really silly question

I have a dynamic PHP script on my page that generates checboxes for a form

So I may have 12 checkboxes..

How can I call them up once submitted via php because if I set a name for them all as

[code]<input type=checkbox name=list value=1>
<input type=checkbox name=list  value=6>
<input type=checkbox name=list value=4>
<input type=checkbox name=list value=13>
<input type=checkbox name=list value=19>[/code]

Obviously I cant do

[b]echo $_POST['list'];[/b]

Because thats only referring to one of those checkboxes. So how can I call them all up by name without naming them differently in the checkbox? The values will always be dynamic by the way

Cheers
Link to comment
https://forums.phpfreaks.com/topic/32016-checkbox/
Share on other sites

[code]<?
if($_SERVER['REQUEST_METHOD']=='POST') {
$a=$_POST['list'];
print_r($a);
}
?>

<form method=POST>
<input type=checkbox name=list[] value=1>
<input type=checkbox name=list[] value=6>
<input type=checkbox name=list[] value=4>
<input type=checkbox name=list[] value=13>
<input type=checkbox name=list[] value=19>
<input type=submit>
</form>
K[/code]
Link to comment
https://forums.phpfreaks.com/topic/32016-checkbox/#findComment-148610
Share on other sites

[code]
<input type=checkbox name=list[] value=1>
<input type=checkbox name=list[]  value=6>
<input type=checkbox name=list[] value=4>
<input type=checkbox name=list[] value=13>
<input type=checkbox name=list[] value=19>
make it an array.
<?
just print the array.
for($i=0; $i< count($_REQUEST['list']); $i++)
{
echo  $_REQUEST['list'][$i];

}
?>
[/code]
Link to comment
https://forums.phpfreaks.com/topic/32016-checkbox/#findComment-148665
Share on other sites

  • 4 weeks later...

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.