HomePHP Performing Strict Validation with the Code Igniter PHP Framework
Performing Strict Validation with the Code Igniter PHP Framework
Welcome to the fifth article in our nine-part series on the Code Igniter framework. In the last article you learned a very simple way to use the framework to check information supplied by users through an HTML form. The type of checking done was very simple, however, and user-supplied data must be checked and validated pretty strictly for many purposes. This article will show you how to improve the previous application's validation mechanism.
Code reusability is a well-known and powerful concept that provides PHP programmers with the capacity for developing complex web applications without having to “reinvent the wheel.” Naturally, in the area dominated by third-party frameworks this concept is really king, since the main goal of a development framework is to accelerate the creation of PHP programs through a set of classes and functions that can be reused any number of times.
Of course, when it comes to picking a particular PHP framework for rapid application development, there’s plenty of options available, and naturally each of them has its own pros and cons. However, before you start scratching your head over which package to choose, you should take a look at Code Igniter (http://codeigniter.com), a piece a software written in PHP 4 that lets you build full-blown PHP applications by using the Model-View-Controller pattern, and best of all, by means of a friendly programming interface.
And speaking of friendly things, you’ll possibly recall that in the previous installment of the series, I explained how to use Code Igniter’s validation class to perform a basic checking process on a simple web form. Essentially, the entire validation procedure was reduced to creating a controller class capable of verifying if each field of the form in question was left empty or not. That’s all.
In addition, based on the result of this process, the controller would either display a simple confirmation web page, or in the worst case, it would redisplay the sample web form, along with an error message indicating which fields should be populated correctly.
But, as I mentioned before, the checking process performed on this online form was pretty simplistic. In this fifth chapter of the series, I’m going to demonstrate how to use Code Igniter’s validation class to validate the data collected through a typical HTML form much more strictly, something that can be very useful for filtering user-supplied information.
Now, it’s time to jump forward and learn in a few easy steps how to perform strict validation on input data with Code Igniter. Let’s get started!