Get form input with $_REQUEST in PHP
Description
The following code shows how to get form input with $_REQUEST.
Example
<?php/*from ww w. jav a 2s . c o m*/
print("<html>\n");
print("<head>\n");
print("<title>Figure 7-2</title>\n");
print("</head>\n");
// if here for the first time
// use white for bgcolor
if(!isset($_REQUEST['color']))
{
$_REQUEST['color'] = "FFFFFF";
}
// open body with background color
print("<body bgcolor=\"#{$_REQUEST['color']}\">\n");
// start form, action is this page itself
print("<form action=\"{$_SERVER['PHP_SELF']}\" " .
"method=\"post\">\n");
// ask for a color
print("<b>HTML color:</b> " .
"<input type=\"text\" name=\"color\" " .
"value=\"{$_REQUEST['color']}\">\n");
// show submit button
print("<input type=\"submit\" value=\"Try It\">\n");
print("</form>\n");
print("</body>\n");
print("</html>\n");
?>
The code above generates the following result.