Using the validation class in PHP
Validation class takes full advantage of encapsulation to hide the mind-bending complexities of the filter constants, flags, and options. If your IDE generates code hints from custom classes, the PHPDoc comments make the arguments easy to use.
Validating user input with the Pos_Validator class involves the following steps:
1. Include the class definition with require_once or __autoload().
2. Create an array of the names of required fields or variables.
3. Instantiate a Pos_Validator object, and pass it the array of required fields (if any). If the values come from the $_GET array, set the input type to get.
4. Pass the name of each input variable to the appropriate validation method.
5. Call the validateInput() method, and capture the array of filtered values in a variable.
6. Call the getMissing() and getErrors() methods, and assign their results to variables.
7. If the getMissing() and getErrors() methods produce empty arrays, you know the input has passed all the validation tests and the filtered array is safe to use. Otherwise, use the error messages generated by getMissing() and getErrors() to alert the user to any mistakes.


LinkBack URL
About LinkBacks
Reply With Quote

LinkBacks Enabled by vBSEO
Bookmarks