Re: Possibly more of an html question, but...
| From: | Kris Dahl | Date: | Mon, 03 Jul 2000 22:30:15 +0000 |
| Subject: | Re: Possibly more of an html question, but... | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-4586@lists.php.net to get a copy of this message | ||
on 7/3/00 2:47 PM, Millaway, John at john@Intersphere.com wrote:
>> Try something like this:
>> <select name="select_test[]" multiple>
>> <option value="selection_1">Number 1
>> <option value="selection_2">Number 2
>> <option value="selection_3">Number 3
>> ...
>> <option value="selection_n">Number n
>> </select>
>>
>> HTML supports an array datatype(sort of).
>
> It's purely a PHP thing. If php sees the name of the variable as "foo[]" it
> creates an array in variable "$foo", and populates it with each value
> corresponding to the parameter named "foo".
>
> The query string could look like this:
> $ø·2§¬
> []¡ªBvô•http://www.bar.com/blah.php4?foo[]=bar&foo[]=whatever&foo[]=blah
Well, it will urlencode the '[' and ']' so it will be like &foo%5a%5b=blah,
or something like that. But it will decode properly when PHP goes to read
it.
Also, just recently I bumped into a problem of doing it this way.
Apparently '[' and ']' are illegal characters for a variable name in
JavaScript. Which means that you can't refer to a multiple select in both
JavaScript and PHP.
I had to write a little function that packed all the selected values of (for
example) 'select_test' into a hidden field of comma separated values--i.e
select_test_array and then parse it when the form was submitted.
Kinda a bummmer, but it worked.
Has anyone figured out a more effective method of referring to a multiple
select in both PHP and Javascript on the same form?
Thanks!
-k