Think SECURITY when processing PHP forms!
These pages will show how to process PHP forms with security in mind. Proper validation of form data is important to protect your form from hackers and spammers!
The HTML form we will be working at in these chapters, contains various input fields: required and optional text fields, radio buttons, and a submit button:
The validation rules for the form above are as follows:Field Validation Rules Name Required. + Must only contain letters and whitespace E-mail Required. + Must contain a valid email address (with
and .) Website Optional. If present, it must contain a valid URL Comment Optional. Multi-line input field (textarea) Gender Required. Must select one
First we will look at the plain HTML code for the form:
The name, email, and website fields are text input elements, and the comment field is a textarea. The HTML code looks like this:
Name: E-mail: Website: Comment: