John is a web developer working through his own company John Dixon Technology Limited. As well as offering web development services, the company also develops and suppies a free accounting package called Earnings Tracker.
When it comes to validating the data that people enter into fields in a form on a web page, JavaScript is quite often used to perform client-side validation. PHP can, however, be used to perform the validation on the server, before the data is processed. This provides a more elegant way of performing the validation because when there is an issue with a particular field, the user is returned to that field rather than a general popup being displayed, which is the way the validation works using JavaScript.
Look at the following form.

This form contains a function at the top of the web page (fieldError) that is called to check whether there is an error for the 'current' field. In this example we only have one field called 'name', but the same function call could be made for as many fields as necessary.
If there is an error for the field, an appropriate error message (see below) is displayed above the field. This is useful because where a form contains several fields, it is sometimes difficult to know to which field a JavaScript-generated error applies.

This script is the form handler. In this example, the only thing the form handler does is to check that the 'name' field is not empty. In a 'real' form handler, the script would go on to process the data in some way once it had been validated.
The $errors array is initially cleared to make sure that any previous errors are removed, otherwise the script would keep thinking that the errors still applied.
After that the $name variable is checked to see if it contains any data. If it is empty, an error message is inserted into the $errors array. A check is then performed to see if the $errors array contains any items; if it does, the user is returned to the form and the error message is displayed above the field.
- Related Videos
- Related Articles
- Ask / Related Q&A




10 Point Website Maintenance Checklist and Annual Website Review
By: Caryl A. Clippinger | 04/01/2010The start of the new year is a great time to take stock of your website and to plan for a better, more useful, and more successful website in the new year. This 10 point website maintenance checklist will get you started to evaluate, assess, and plan for a better year for your website and your business.
Importance of Colors in Web Design and Branding
By: arvind | 04/01/2010Color is the main feature in Web design. No matter whether it is a major corporation, an individual firm or a small organization, color format or scheme is the most important aspect in the appearance and giving look to the website.
How to Make A Website By the Numbers
By: Benjamin J. Thomas | 04/01/2010You’ve been thinking about it for a while now and it is finally time to learn how to make a website. If you think making a website is difficult, you might be surprised to learn that it is a rather straight forward process.
Website Design Albuquerque: If You Want the Best in Web Design, Albuquerque Has It
By: Vikram kuamr | 04/01/2010Even if you are not a resident of Albuquerque or New Mexico, you are still able to use a web design, Albuquerque company for assistance with your website.
How You Can Use Web Design Albuquerque to Build Your Online Presence
By: Vikram kuamr | 04/01/2010It is important to use the services of a professional company in web design Albuquerque if you want a website for your business that looks professional.
Website Design Strategy For Increased Traffic
By: beyli | 04/01/2010Learning website design strategies for increased traffic can help small business website owners succeed online. Obtaining a winning website is obviously the goal for any small business owner online and get the traffic needed to turn visitors into return customers. Providing quality content is important to get indexed by search engines and get your website high in the rankings over your competition.
Responsibilities of a Good Web Hosting Company
By: Ryan Hudson | 04/01/2010The hosting company that suffices for all the website requirements of its users is a good web hosting company. Good services can result in impressed users recommending the name of the particular company in their respective social circles. Hence, a web hosting company has a clear cut responsibility flow chart to follow.
ASP.Net or PHP – Which is a better web programming language
By: Cyril Britto | 04/01/2010PHP is considered to be the most effective web programming language since it is an open source programming language and millions of programmers use this.
Using Php to Validate Form Fields
By: John Dixon | 24/07/2008 | Web DesignThis article explains how to use PHP to validate data entered in form fields on a web page.
Finding Hidden Characters in a File
By: John Dixon | 27/06/2008 | ProgrammingIt is sometimes necessary to find hidden characters within one or more files.
Web Site Promotion Tips
By: John Dixon | 20/06/2008 | SEOWhen trying to get to the top of the search engine rankings there are certain things you should do, and other things you should not, in order to increase your chances of getting a top ten placement.
Exploiting Google Adsense
By: John Dixon | 08/04/2008 | Internet MarketingGoogle Adsense provides a great way to generate revenue from a web site.
Using Perl and Regular Expressions to Process Html Files - Part 2
By: John Dixon | 17/03/2008 | ProgrammingIn Part 1 we looked at what Perl and regular expressions are, and discussed how to use them to process ASCII files such as HTML files. In this part we'll develop a Perl script to process an HTML file.
Using Perl and Regular Expressions to Process Html Files - Part 1
By: John Dixon | 17/03/2008 | ProgrammingLike many web content authors, over the past few years I've had many occasions when I've needed to clean up a bunch of HTML files that have been generated by a word processor or publishing package. Initially, I used to clean up the files manually, opening each one in turn, and making the same set of updates to each one. This works fine when you only have a few files to fix, but when you have hundreds or even thousands to do, you can very quickly be looking at weeks or even months of work.
Size Really Does Matter
By: John Dixon | 14/03/2008 | SEOI believe that by following three basic rules, it is relatively easy to achieve a high ranking with the major search engines: 1. Add lots of relevant content; 2. Build up plenty of good quality inbound links; 3. Be patient.