iterating form variables in php
Posted: Mon May 26, 2003 6:23 am
I need an example of code that iterates variables in a form in php - something equivalent to the "Request.Form.count" or "Request.Form.Key(i)" in ASP.
A community of PHP developers offering assistance, advice, discussion, and friendship.
http://forums.devnetwork.net/
Code: Select all
<?php
if($_POST)
{
foreach($_POST as $key=>$value)
printf "$key: $value";
}
?>Code: Select all
<html>
<head><title>request iteration example</title></head>
<body>
<fieldset><legend>$_REQUEST</legend>
<pre><?php print_r($_REQUEST); ?></pre>
</fieldset>
<fieldset><legend>$_POST</legend>
<pre>
<?php
foreach($_POST as $key=>$value)
echo $key, '=>', $value, "\n";
?>
</pre>
</fieldset>
<fieldset><legend>$_GET</legend>
<pre>
<?php
foreach($_GET as $key=>$value)
echo $key, '=>', $value, "\n";
?>
</pre>
</fieldset>
<?php echo 'parameter <i>p1</i> has ', isset($_POST['p1']) ? 'been sent' : 'not been sent'; ?>
<hr />
<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="POST" style="background-color: silver;">
<label for="p1">checkbox #1</label><input type="checkbox" id="p1" name="p1" /><br />
<label for="p2">checkbox #2</label><input type="checkbox" id="p2" name="p2" /><br />
<label for="p3">checkbox #3</label><input type="checkbox" id="p3" name="p3" /><br />
<label for="p4">checkbox #4</label><input type="checkbox" id="p4" name="p4" /><br />
<input type="submit" />
</form>
<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="GET" style="background-color: grey;">
<label for="g1">checkbox #1</label><input type="checkbox" id="g1" name="g1" /><br />
<label for="g2">checkbox #2</label><input type="checkbox" id="g2" name="g2" /><br />
<label for="g3">checkbox #3</label><input type="checkbox" id="g3" name="g3" /><br />
<label for="g4">checkbox #4</label><input type="checkbox" id="g4" name="g4" /><br />
<input type="submit" />
</form>
</body>
</html>