Jump to content

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...
This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.