So that takes care of the basic validation routines. As you can see, it's fairly easy to add new ones to the class, as per your specific requirements. All that's left now are a couple of methods to access the error list. The first of these is a simple little method named isError(), which lets you know whether or not any errors have occurred yet. Internally, all this method does is check the size of the $_errorList array; if the size of the array is greater than 1, it implies that one or more errors have occurred while validating the form data. Take a look: Of course, all isError() does is tell you whether or not an error occurred; it won't let you view the list of errors. For that, you need the getErrorList() method, which returns the current $_errorList array. Short and sweet! Finally, how about resetting the error list? Well, that's why I have the resetErrorList() method, which clears the $_errorList array of all data. It's a good idea to run this resetErrorList() method whenever the class is first instantiated - which is why I've added it to the class constructor. In case you didn't already know, PHP makes it possible to automatically execute a specific function when a new instance of a class is spawned. This function is referred to as a "constructor" and must have the same name as the class. Which, if you look at the code above, is exactly what I've done.
blog comments powered by Disqus |