linuxStat PHP Documentation

Collection of web form data

A web form contains various types of elements to collect data from users.
We will consider each element type and describe how data from the element
type can be obtained in a PHP program.

Textbox

A textbox can be used to provide text data in a web form.
It has the following appearance in a web form.

First Name:


The user types in her first name in the textbox then she presses the Submit button.


An HTML document containing the above textbox element 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="#6B7E23" text="#FFFF00" lang=EN-US>
<form action="textbox.php" method="get">
First Name: <input type="text" name="first" /><br>
<input type="submit" name="Submit" value="Submit" size="30" />
</form><br>
</body>
</html>

When the user presses the Submit button, the PHP interpreter
executes a PHP program contained in the file textbox.php.
Before the PHP program in textbox.php is executed, a map called _GET is
constructed. The text typed in by the user is the value given by the name
first in the _GET map. Thus,
$_GET["first"]
will give the text typed in 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 textbox.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="#6B7E23" text="#FFFF00" lang=EN-US>
<?php
# Example of textbox data in _GET map
print "You typed in: {$_GET["first"]} <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