/    Sign up×
Community /Pin to ProfileBookmark

Creating an array from a count???

Hi,

If i have a list of check boxes table_0, table_1, table_2 ect…

When i click submit on the form,on the page it is going to how can I then create an array of the check boxes that are checked.

All the check boxes are named 0,1,2,3, so on until they are all there.

Any Ideas

Adam

to post a comment
PHP

2 Comments(s)

Copy linkTweet thisAlerts:
@NogDogAug 17.2005 — Probably the simplest thing would be to name all the input checkbox elements with the same name followed by "[]" so that PHP puts them all into an array within the $_POST array:

[code=php]
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html lang='en'>
<head>
<META HTTP-EQUIV='Content-Type' CONTENT='text/html; charset=ISO-8859-1'>
<title>Page title</title>
<style type="text/css">
<!--
fieldset p { margin: 0.3em 0; }
-->
</style>
</head>
<body>
<form action="<?php echo $_SERVER['PHP_SELF'] ?>" method="post">
<fieldset>
<legend>Checkbox Test</legend>
<p><label><input type="checkbox" name="check[]" value="checkbox 1">
Box 1</label></p>
<p><label><input type="checkbox" name="check[]" value="checkbox 2">
Box 2</label></p>
<p><label><input type="checkbox" name="check[]" value="checkbox 3">
Box 3</label></p>
<p><label><input type="checkbox" name="check[]" value="checkbox 4">
Box 4</label></p>
<p><label><input type="checkbox" name="check[]" value="checkbox 5">
Box 5</label></p>
<p><input type="submit" value="Submit" name="submit"></p>
</fieldset>
</form>
<?php
if(isset($_POST['submit']))
{
echo "<p>You selelcted:</p>n<ul>n";
foreach($_POST['check'] as $value)
{
echo "<li>$value</li>n";
}
}
?>
</body>
</html>
[/code]
Copy linkTweet thisAlerts:
@k0r54authorAug 17.2005 — now why didn't i think of that lol ?

That brill ? thanks very much

Adam
×

Success!

Help @k0r54 spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 6.18,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @nearjob,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,
)...