Re: form vars
| From: | Nick Talbott | Date: | Tue, 27 Jun 2000 10:13:51 +0000 |
| Subject: | Re: form vars | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-3303@lists.php.net to get a copy of this message | ||
Kevin
>Is there a way with php3 to round up all vars sent to a script via a
>form. Ideally I'll whip them all up into an associative array.
>
>I have too many form vars and don't want to have to test to see if
>each one has a value.
Assuming you POST the form variables, then the data will be in the
associative array $HTTP_POST_VARS. Here's an example of code I use to
simply print out every variable POSTed by a form. This code can also cope
with an array from a form. The code shows a way of looping through each
variable, which you could adapt to do whatever you need to do.
for( reset($HTTP_POST_VARS);
$key = key($HTTP_POST_VARS);
next($HTTP_POST_VARS) )
{
if ( is_array($HTTP_POST_VARS[$key]) )
{
$num=count($HTTP_POST_VARS[$key]);
for ($i=0; $i<$num; $i++)
print "$$key"."[$i] = ".
$HTTP_POST_VARS[$key][$i].
"<br>\n";
}
else
{
print "$$key = ".
$HTTP_POST_VARS[$key].
"<br>\n";
}
}
Hope this helps - Nick
Nick Talbott
IT Policy and Strategy Manager, Powys County Council, UK
email nickt@powys.gov.uk
FAX +44 (0) 1597 824781
web http://www.powys.gov.uk and http://www.powysweb.co.uk