PHP DevCenter

oreilly.comSafari Books Online.Conferences.

We've expanded our LAMP news coverage and improved our search! Search for all things LAMP across O'Reilly!

Search
Search Tips

advertisement

Listen Print Subscribe to PHP Subscribe to Newsletters

Phorm Manager
Pages: 1, 2, 3

Validation

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 FirstName and 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.

Related Reading

PHP Pocket ReferencePHP Pocket Reference
By Rasmus Lerdorf
Table of Contents
Sample Section
Full Description
Read Online -- Safari

<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 CheckZipCode.

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.

Sample Scripts

Demonstration Form/Script

Form Template

Phorm Manager Source Code

References

NuSphere

PHP.net

NuSphere

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;

Summary

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.




Tagged Articles

Be the first to post this article to del.icio.us

Sponsored Resources

  • Inside Lightroom
Advertisement

Sponsored by:

O'Reilly Media

©2009, O'Reilly Media, Inc.
(707) 827-7000 / (800) 998-9938
All trademarks and registered trademarks appearing on oreilly.com are the property of their respective owners.
About O'Reilly
Academic Solutions
Authors
Contacts
Customer Service
Jobs
Newsletters
O'Reilly Labs
Press Room
Privacy Policy
RSS Feeds
Terms of Service
User Groups
Writing for O'Reilly
Content Archive
Business Technology
Computer Technology
Google
Microsoft
Mobile
Network
Operating System
Digital Photography
Programming
Software
Web
Web Design
More O'Reilly Sites
O'Reilly Radar
Ignite
Tools of Change for Publishing
Digital Media
Inside iPhone
O'Reilly FYI
makezine.com
craftzine.com
hackszine.com
perl.com
xml.com

Partner Sites
InsideRIA
java.net
O'Reilly Insights on Forbes.com