The Phorm Manager optionally performs four types of validation. The most frequently used is simply to prevent a null input in a specific field. The hidden field
Required contains a comma-separated list of field names to be checked. An example would be:
<INPUT TYPE="HIDDEN" NAME="Required" VALUE="FirstName,LastName">
The form variables
LastName will not be processed unless they both have a non-null value.
A second type of validation is e-mail addresses. As a practical matter, e-mail addresses cannot be checked in real time. A mail server may be temporarily down or unreachable. Failure to contact a remote mail server doesn't mean the address is invalid. What the function ValidateEmail() does is use a regular expression to determine if the supplied address is in the correct format. Although interposed characters will not be detected, it will catch the majority of common errors like a missing
@ or invalid characters. Again, a comma-delimited list contained in a hidden field named "CheckEmail" determines which of the form's fields are to be validated.
<INPUT TYPE="HIDDEN" NAME="CheckEmail" VALUE="TestEmailAddress">
The third type of validation is US ZIP code. Again, the input is only checked for valid formatting. There are many potential but unused ZIP codes that would be passed by the
ValidateZipCode() function. However, the function will check for either 5-digit or 9-digit ZIP codes. Designated fields requiring validation are passed as a comma-delimited list in
a hidden field named
The last validation uses the function
CheckNumeric() to validate numeric fields. It will pass either integer or floating-point numbers but will not pass numbers with formatting such as 1,234.66. Once again, a comma-delimited list contained in a hidden field named
CheckNumeric will cause numeric validation of these fields.
In the last article, the Phanatic introduced NuSphere. This easy-to-install package contains Apache, PHP, Perl, and MySQL. Having all of this functionality on my PC saved an immense amount of time while developing this application. There was no need to keep uploading files to a web site, testing, and repeating the process. All that was required was to edit, save, and run. Check the last column for a complete description and installation details.
If you want to use PHP to send mail from your PC, you have to configure an SMTP server. In the path
C:\nusphere\apache\php (assuming you took the default path when installing) is a file named
php.ini. Edit the following line with your mail server.
SMTP = mail-server-host-and-domain-name;
So there we have it, PHP fans. A generic form processor with more bells and whistles than the Trans Siberian Express. It has been a challenging and fun project. The Phanatic aims to please even though there are times when he is not a good shot.
If you would add any enhancements, or would like to see some enhancements, or just have some comments, drop me a note. As usual, please let me know what types of things you would like to see in future articles.
Urb LeJeune is a 25-year programming veteran with over 10 years of Internet experience thrown in for good measure.
Read more PHP Forms columns.
Discuss this article in the O'Reilly Network PHP Forum.
Return to the PHP DevCenter.