[thelist] dump question, but...

Keith Gaughan keith at digital-crew.com
Fri Jun 10 11:32:44 CDT 2005


-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Michele Foster - WizarDev wrote:

> What are the brackets doing in the name attribute?  That could be the
> problem right there. The value being passed would then be housecond[]=1, and
> not housecond=1.
> 
> Also, if all of your checkboxes are using the same name, then the string
> being passed when submitted, probably looks something like,
> housecond[]=1,3,5.  In which case, you will either have to split that into
> an array in order to get the single values (I don't do it this way), or
> check if the value is in the string.  In ASP, it's the instr function .. I
> don't know what it would be in PHP.
> 
> If I'm way off base, perhaps more info is needed.  :)

That's actually ok.

Just to convince yourself, make a form something like this:

    <form method="get" action="#">
    <input type="checkbox" name="foo" value="bar"/>
    <input type="checkbox" name="foo" value="baz"/>
    <input type="submit"/>
    </form>

And dump it in a HTML file (no need for a server-side preprocessor such
as PHP, ASP, CF, or whatever).

Check the two boxes, and click submit. Your URL should look something
like this:

    blah.html?foo[]=bar&foo[]=baz

What PHP does is, if you've got parameters like this (be it a POST
request or a GET request) and the name of the parameter ends in `[]',
it will put them all into an array. If there's none, it does what
everything else does and concatenates them together into a
comma-seperated list.

So you can address the contents of those checkboxes by doing something
like this:

    $_GET["foo"][0] -- The first one,
    $_GET["foo"][1] -- The second one, &c.

Notice that the square brackets have been stripped from the parameter
name.

K.
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.1 (MingW32)
Comment: Using GnuPG with Thunderbird - http://enigmail.mozdev.org

iD8DBQFCqcCsmSWF0pzlQ04RAtYlAKCl8N76TlFnqavKItOrBLXw9FzorQCfTi0g
9FZhttvjdQ/LbaZqmyGIPFw=
=yehm
-----END PGP SIGNATURE-----


More information about the thelist mailing list