Souping Up the Script

You can soup up this script to be smarter:

Check for Spaces

This script as it currently is can be easily fooled if a user just enters spaces in each of the fields. In the check_form script on lines 46 and 50, we check to see if the user entered anything. This includes spaces. If we want to make sure the users enter characters (not just spaces), we could check like this:

if(ereg("^ +", $last)) { 
    $error[last] = true;
    $print_again = true;
}

Basically, the ereg() function is checking the $last variable to see if it starts with one or more spaces. We'll take a closer look at the ereg() function a little later in this chapter.

Check for Minimum Number of Characters

Sometimes you may want to make sure the user enters a minimum ...

Get Advanced PHP for Web Professionals now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.