linuxStat PHP Documentation

Collection of data from radio buttons in a form

Radio buttons are used to select a single option from a number of options.
It has the following appearance in a web form.

Provide your annual income range:
below $30000
$30000 - $50000
$50000 - $70000
above $70000



The user selects one of the four options then
she presses the Submit button.


An HTML document containing the above radio buttons 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="checkincome.php" method="get">
Provide your annual income range:<br>
<input type="radio" name="IncomeRange" value="below 30">below $30000<br>
<input type="radio" name="IncomeRange" value="30 - 50">$30000 - $50000<br>
<input type="radio" name="IncomeRange" value="50 - 70">$50000 - $70000<br>
<input type="radio" name="IncomeRange" value="above 70">above $70000<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 checkincome.php.
Before the PHP program in checkincome.php is executed, a map called _GET is
constructed. The value corresponding to the selection made by the user
is given by the name IncomeRange in the _GET map. Thus,
$_GET["IncomeRange"]
will give the value corresponding to the selection made by the user.

We will construct a PHP program that will echo back the text typed
in by the user as follows and save it in checkincome.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 radio button data in _GET map
print "You selected: {$_GET["IncomeRange"]} <br>";
?>
</body>
</html>


Click the following link to execute the above PHP code
by my server's PHP interpreter.

Try the above example   Next   Index