HomePHP Developing a Form Validation System with the Observer Pattern in PHP
Developing a Form Validation System with the Observer Pattern in PHP
Want to gain a good grounding in how to apply the Observer pattern in PHP? Then you’re in the right place! Welcome to the second part of the series “The Observer Pattern in PHP.” Composed of three tutorials, this series teaches you the key concepts of the popular Observer design pattern, and shows you how to apply it in the context of real-world PHP applications.
Okay, after introducing the topics treated over the course of this series, let’s quickly recapitulate the concepts that I deployed in the first tutorial so you can understand this second article more easily.
As you’ll hopefully remember, in the previous part I went through the implementation of the Observer pattern in PHP 5 by coding a basic example. The example demonstrated in an easygoing fashion how the different objects that make up a specific program can be decoupled from the rest of the application, in this way clearly delineating their scope.
Regarding this particular example, the implementation of the Observer pattern allowed me to develop a message handling system capable of reflecting certain changes generated by independent objects at the application’s core level. Indeed, the application of this pattern is one of the best approaches available today for constructing truly independent objects, as well as building systems that expose a centralized mechanism for making decisions according to the changes introduced by disparate components.
Well, after refreshing some of the most important points regarding the creation of observer objects, let’s focus our attention on the subject of this second tutorial. Over the next few lines, I’ll be demonstrating how to apply the Observer pattern during the development of a real-world application: a form validation system.
Based on this approach, hopefully you’ll learn quickly how to validate input data by using the Observer pattern. Are you interested in learning how this can be achieved with PHP? Fine, start right now reading the next section!