Prev | Current Page 417 | Next

W. Jason Gilmore

"Beginning PHP and MySQL: From Novice to Professional"

com will soon be a spam-magnet!
In this example the form refers to the script in which it is found, rather than
another script. Although both practices are regularly employed, it??™s quite commonplace
to refer to the originating document and use conditional logic to determine
which actions should be performed. In this case, the conditional logic dictates that the
echo statements will only occur if the user has submitted (posted) the form.
In cases where you??™re posting data back to the same script from which it originated,
as in the preceding example, you can use the PHP superglobal variable
$_SERVER['PHP_SELF']. The name of the executing script is automatically assigned
to this variable; therefore, using it in place of the actual file name will save some
additional code modification should the file name later change. For example, the
tag in the preceding example could be modified as follows and still produce
the same outcome:

Passing Form Data to a Function
The process for passing form data to a function is identical to the process for passing any
other variable; you simply pass the posted form data as function parameters. Suppose
you want to incorporate some server-side validation into the previous example, using a
custom function to verify the e-mail address??™s syntactical validity. Listing 13-1 presents
the revised script.


Pages:
405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429