This is a nice easy one :)

It couldn't be simpler.

Just put empty square brackets (as used in arrays) in front of your
checkbox name.
The example below assumes you have PHP 4.1 or greater (which uses
$_POST to contain form posted data)
notice how name="ck[]"


<html>
<head>
        <title>Untitled</title>
</head>

<body>
<?php 
    if(count($_POST)) {
        foreach ($_POST["ck"] as $varval) {
            print("<div>".$varval."</div>");
        }
    }
?>

<form action="test.php" method="post">


<input type="checkbox" name="ck[]" value="val1"><br>
<input type="checkbox" name="ck[]" value="val2"><br>
<input type="checkbox" name="ck[]" value="val3"><br>
<input type="checkbox" name="ck[]" value="val4"><br>
<input type="checkbox" name="ck[]" value="val5"><br>
<input type="submit">
</form>


</body>
</html>


in earlier versions of PHP, $_POST["ck"] would be equal to $ck
(although, the former is safer)


On Thu, 4 Jul 2002 10:52:37 +0200, "Uwe Birkenhain"
<[EMAIL PROTECTED]> said:
> Hi everybody on this rainy morning!
> 
> My problem:
> I give the user a form with a list of options with checkboxes.
> The list is long and not predictable - the values change always.
> I want to put the checked values (or all, that doesn't matter) in an
> array,
> to pass it to my function.
> 
> How can I write those keys and values in an array?
> 
> I suppose it will be best done with JS - but since I don't know JS ...
> Has anybody a ready solution?
> 
> Thank's a lot!
> 
> Uwe
> 
> 
> 
> -- 
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
> 
> 

[TK]

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to