10.7.1
I would like to write a generic PHP script that can handle data coming
from any form. How do I know which POST method variables are available?
PHP offers many
predefined variables , like the superglobal
$_POST
. You may loop through
$_POST
as it's an associate array of all POSTed values. For example, let's
simply loop through it with
foreach , check for
empty
values,
and print them out.
<?php $empty = $post = array(); foreach ($_POST as $varname => $varvalue) { if (empty($varvalue)) { $empty[$varname] = $varvalue; } else { $post[$varname] = $varvalue; } }
print "<pre>"; if (empty($empty)) { print "None of the POSTed values are empty, posted:\n"; var_dump($post); } else { print "We have " . count($empty) . " empty values\n"; print "Posted:\n"; var_dump($post); print "Empty:\n"; var_dump($empty); exit; } ?>
Note | Superglobales : disponiblité
Depuis PHP 4.1.0, les tableaux superglobaux tels que
$_GET
,
$_POST
et
$_SERVER
, etc... sont disponibles. Pour plus d'informations, lisez la section superglobals
|
|