Jump to content

Archived

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

gardan06

form post checkbox values

Recommended Posts

im testing getting checkbox values. here is test.php:

[quote]<form method="post" name="form1" action="test2.php">
Likes: <p>
<input type="checkbox" name="like[]" value="mustard" />Mustard<br />
<input type="checkbox" name="like[]" value="broccoli" />Broccoli<br />
<input type="checkbox" name="like[]" value="women" />Women<br />
<input type="checkbox" name="like[]" value="men" />Men<br />
<input type="checkbox" name="like[]" value="catsup" />Catsup<br />
<input type="checkbox" name="like[]" value="magazine" />Magazines<br />
<p><input type="submit" value="Submit">
</form>[/quote]

and this is test2.php:

[quote]<?
$ctr = count($_POST['like']);
//echo "count = ".$ctr."<p>";//die();
$like = array();
for ($i=0;$i<5;$i++) {
echo "post = ".$_POST['like'.$i]."<br>";
}
?>[/quote]

Share this post


Link to post
Share on other sites
Rather than using a for loop it'll be better if you use a foreach loop:

[code=php:0]foreach($_POST['like'] as $key => $value)
{
    echo "post = " . $value;
}[/code]

Share this post


Link to post
Share on other sites

×

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.