note 49116 added to language.variables.external
| From: | (__ignoreunderscores) | Date: | Mon, 17 Jan 2005 11:05:45 +0000 |
| Subject: | note 49116 added to language.variables.external | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-83487@lists.php.net to get a copy of this message | ||
Hi all:
I'm presently building a solution to programmatically build, view, and validate HTML forms when
I came across the ol' PHP non-scalar form variable handling problem. Because my form validator
class would really have no way of knowing if a given form variable was meant to be scalar or not, I
decided to TREAT ALL PHP FORM VARIABLES AS ARRAYS, i.e., to use the '[]' syntax for all
variables, scalar or not. This way, the form designer need not remember to specify the
'[]' syntax, and the Form->HTML transformer need not scan for every input within the
form, looking for duplicate names. This also eliminates the risk of losing data you meant to keep
in an array but to which you forgot to apply the '[]' syntax.
You may then either treat all form variables as arrays in your form handling code, or you may, as I
intend to do, filter each HTML request through a Front Controller (desc. in Fowler, PoEAA). The
Front Controller would convert all arrays of length 1 to a scalar variable and leave multi-element
arrays as they are. This should essentially convert PHP's handling of non-scalar form
variables to that of ASP's (or slightly better, since multiple form values of the same name
will actually be arrays, not just comma-seperated values).
This way my Form Validator class can just check if the input to validate is an array, and then apply
some constraint across each element in the array.
----
Manual Page -- http://www.php.net/manual/en/language.variables.external.php
Edit -- http://master.php.net/manage/user-notes.php?action=edit+49116
Delete: added to the manual -- http://master.php.net/manage/user-notes.php?action=delete+49116&report=yes&reason=added+to+the+manual
Delete: bad code -- http://master.php.net/manage/user-notes.php?action=delete+49116&report=yes&reason=bad+code
Delete: spam -- http://master.php.net/manage/user-notes.php?action=delete+49116&report=yes&reason=spam
Delete: useless -- http://master.php.net/manage/user-notes.php?action=delete+49116&report=yes&reason=useless+example
Delete: other reasons -- http://master.php.net/manage/user-notes.php?action=delete+49116&report=yes
Reject -- http://master.php.net/manage/user-notes.php?action=reject+49116&report=yes
Search -- http://master.php.net/manage/user-notes.php