linuxStat PHP Documentation
Collection of data from check boxes in a form
Check boxes are used to select one or more from multiple choices.
It has the following appearance in a web form.
The user selects one or more of the five choices then
she presses the Submit button.
An HTML document containing the above check boxes is the following.
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/transitional.dtd">
<html>
<head>
<meta http-equiv=Content-Type content="text/html; charset=us-ascii">
<title>Executed on Dell Server, Intel Processor, created on HP laptop</title>
</head>
<body bgcolor="#0F243E" text="#FFFF00" lang=EN-US>
<form action="getinvestorsinterest.php" method="get">
Investment Interest:<br><br>
<input type="checkbox" name="InvIntDS" value="Domestic Stock">Domestic stock funds<br>
<input type="checkbox" name="InvIntGS" value="Global Stock">Global stock funds<br>
<input type="checkbox" name="InvIntDB" value="Domestic Bond">Domestic bond funds<br>
<input type="checkbox" name="InvIntGB" value="Global Bond">Global bond funds<br>
<input type="checkbox" name="InvIntMM" value="Money Market">Money market funds<br>
<br><br>
<input type="submit" name="Submit" value="Submit" size="30">
</form>
</body>
</html>
When the user presses the Submit button, the PHP code interpreter
executes a PHP program contained in the file getinvestorsinterest.php.
Before the PHP program in getinvestorsinterest.php is executed,
a map called _GET is
constructed. The values corresponding to the selections
made by the user are given in the _GET map. Thus,
$_GET["InvIntDS"]
$_GET["InvIntGS"]
$_GET["InvIntDB"]
$_GET["InvIntGB"]
$_GET["InvIntMM"]
will give the values corresponding to the selections made by the user.
We will construct a PHP program that will echo back the selections made
by the user as follows and save it in getinvestorsinterest.php file.
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/transitional.dtd">
<html>
<head>
<meta http-equiv=Content-Type content="text/html; charset=us-ascii">
<title>Executed on Dell Server, Intel Processor, created on HP laptop</title>
</head>
<body bgcolor="#0F243E" text="#FFFF00" lang=EN-US>
<?php
# Example of check box data in _GET map
print "Your interests are: {$_GET["InvIntDS"]}, {$_GET["InvIntGS"]}, {$_GET["InvIntDB"]}, {$_GET["InvIntGB"]}, {$_GET["InvIntMM"]} fund <br>";
?>
</body>
</html>
Click the following link to execute the above PHP program
by my server's PHP interpreter.
Try the above example Next Index