note 75619 added to function.filter-input-array
| From: | iam4webwork at NOSPAM dot hotmail dot com | Date: | Fri, 08 Jun 2007 08:02:52 +0000 |
| Subject: | note 75619 added to function.filter-input-array | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-127290@lists.php.net to get a copy of this message | ||
The above example raises other questions such as how one would validate an html array. In the input
form each input tag that refers to an html array would be named for example testarray[]. However,
after the form is submitted, the syntax for validating the values is different from the expected
$_POST['testarray[]']. Instead one has to drop the braces and validate as follows,
assuming that testarray[] is supposed to be an html array of numerical values:
Valid test:
echo '*';
echo filter_input(
INPUT_POST,
'testarray',
FILTER_VALIDATE_INT,
FILTER_REQUIRE_ARRAY
);
echo '*';
But the following is an invalid test that results in 2 consequtive asterisks only!
echo '*';
echo filter_input(INPUT_POST,
'testarray[]',
FILTER_VALIDATE_INT,
FILTER_REQUIRE_ARRAY
);
echo '*';
So, there is a naming inconsistency going on, as after the form is submitted, one has to forget
about the original name of the submitted array by dropping its braces. Maybe when the PECL/Filter
extension is reviewed again, the great ones might consider making the syntax a little more
forgiving.
----
Server IP: 64.71.164.2
Probable Submitter: 216.244.41.96
----
Manual Page -- http://www.php.net/manual/en/function.filter-input-array.php
Edit -- https://master.php.net/note/edit/75619
Del: integrated -- https://master.php.net/note/delete/75619/integrated
Del: useless -- https://master.php.net/note/delete/75619/useless
Del: bad code -- https://master.php.net/note/delete/75619/bad+code
Del: spam -- https://master.php.net/note/delete/75619/spam
Del: non-english -- https://master.php.net/note/delete/75619/non-english
Del: in docs -- https://master.php.net/note/delete/75619/in+docs
Del: other reasons-- https://master.php.net/note/delete/75619
Reject -- https://master.php.net/note/reject/75619
Search -- https://master.php.net/manage/user-notes.php