You can learn more about filtering user input for safe
publication and storage in Chapter 21.
CHAPTER 13 ?– FORMS 351
Keep in mind that, other than the odd format, $_POST variables are just like any
other variable. They??™re simply referenced in this fashion in an effort to definitively
compartmentalize an external variable??™s origination. As you learned in Chapter 3,
such a convention is available for variables originating from the GET method, cookies,
sessions, the server, and uploaded files. For those of you with an object-oriented
background, think of it as namespaces for variables.
This section introduces numerous scenarios in which PHP can play a highly effective
role not only in managing form data but also in actually creating the form itself. For
starters, though, let??™s take a look at a simple example.
A Simple Example
The following script renders a form that prompts the user for his name and e-mail
address. Once completed and submitted, the script (named subscribe.php) displays
this information back to the browser window.
// If the name field is filled in
if (isset($_POST['name']))
{
$name = htmlentities($_POST['name']);
$email = htmlentities($_POST['email']);
printf("Hi %s!
", $name);
printf("The address %s will soon be a spam-magnet!
", $email);
}
?>
352 CHAPTER 13 ?– FORMS
Assuming that the user completes both fields and clicks the Go! button, output
similar to the following will be displayed:
Hi Bill!
The address bill@example.
Pages:
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428