form variable name question
| From: | Monte Ohrt | Date: | Thu, 03 Jun 1999 14:38:35 +0000 |
| Subject: | form variable name question | ||
| Groups: | php.dev | ||
| Request: | Send a blank email to php-dev+get-6513@lists.php.net to get a copy of this message | ||
Hello,
This is a question regarding form variables of the same name. According
to the documentation, the variable must have "[]" at the end of its name
in order for it to be interpreted as an array.
example:
<INPUT type=hidden name=user_ids value="123">
<INPUT type=hidden name=user_ids value="456">
<INPUT type=hidden name=user_ids value="789">
(returns last value)
<INPUT type=hidden name=user_ids[] value="123">
<INPUT type=hidden name=user_ids[] value="456">
<INPUT type=hidden name=user_ids[] value="789">
(returns array of values)
This seems to work fine, except when you try using javascript with these
variable names. Depending on what you are trying to do, javascript can
come up with syntax errors with "[]" in the variable name, and there
isn't an easy way around it.
I'm just wondering, why was the decision made to require "[]" in the
variable name to return as an array? Is there an issue where PHP cannot
determine the variable type on its own? I don't see a good reason for
this limitation. If you want the last value, then the sensible solution
would be to grab it off the end of the returned array after the form is
submitted.
Monte