Validating form data php

A common web task in web application development is to validate data input by a user.

This allows a user to scan down a form and fix all their errors in a single pass.

To accomplish this, I use an array called $form_errors.

This is because I generally only want to display one error per field or because failing one validation may make other rules invalid.

For example, if a required field is left blank, you want to display that the field is required.

It is also a good security practice to limit the data that a web based form will accept.

While it is common in web 2.0 applications to use client side code such as Javascript to validate form fields, this should not be relied on for a number of reasons.It is not necessary to show errors regarding format or data type at this stage.I display errors in the label of the form field between tags.These libraries can be great time savers but for various reasons, you may need to write your own form validation routines.When validating form data, it is likely that a user will submit something that does not pass the validation routine.Some users disable Javascript so you want to provide a working interface for these users.

Tags: , ,