This document discusses various aspects of working with web forms in PHP, including:
1) Useful server variables for forms like QUERY_STRING and SERVER_NAME.
2) Accessing form parameters submitted to the server.
3) Processing forms with functions, including validating form data with techniques like checking for required fields and valid email addresses.
4) Displaying default values or error messages for form fields.
5) Stripping HTML tags from form inputs and encoding special characters for safe display.
The document provides examples of implementing each of these techniques.
1. Making Web Forms
Useful Server Variables
Accessing Form Parameters
Form Processing with Functions
Validating Data
Displaying Default Values
Putting It All Together
7. Useful Server Variables
• Aside from PHP_SELF auto global array $_SERVER
contains number of useful elements
– QUERY_STRING
– PATH_INFO
– SERVER_NAME
– DOCUMENT_ROOT
– REMOTE_ADDR
– REMOTE_HOST
– HTTP_REFERRER
– HTTP_USER_AGENT
8. Accessing Form Parameters
• A two-element form
• Printing submitted form parameters
• Multiple-valued form elements
• Accessing multiple submitted values
53. • If $_POST['comments'] contains
• I <b>love</b> sweet <div>rice</div> & tea.
• It prints
• I <b>love</b> sweet <div
>rice</fancy>& tea.
54. • The characters that have a special meanings in
HTML (<, >, &, and ") are changed into their
entity equivalents:
– < to <
– > to >
– & to &
– " to "
55. Displaying Default Values
• Building an array of defaults
• Setting a default value in a text box
• Setting a default value in a multiline text area
• Setting a default value in a <select> menu
• Setting defaults in a multivalued <select>
menu
• Setting defaults for checkboxes and radio
buttons