OverviewObjectiveLearn how to create custom validation in ProdigyView.Requirements Understanding of validation Understanding of anonymous functionsEstimated Time8 Minutes www.prodigyview.com
Follow Along With Code Example1. Download a copy of the example code at www.prodigyview.com/source.2. Install the system in an environment you feel comfortable testing in.3. Proceed to examples/util/Validation_Custom.php
What is custom validation?Building off of the tutorial on validation basics, we learnedabout the built in validation rules in ProdigyView. But thereis a plethora of things to validate that the PVValidatordoes not have, such as credit card validation. How do weovercome this problem? The Answer Add our own validation
Checking and AddingThe two methods to understand when writing customvalidation are addRule() and check().addRule()Adds a rule to the validator. The rule has a name andparameters that define a rule. The rules can be writtenusing preg_match or anonymous functions.Check()Checks passed values against and should return true orfalse.
Check ExampleOur first example will be using the method check(). Wewill use one of the built checks, integer, which checks if anumber is an int. The rule to use when checking The value to check Returns false because not an integer
Create Function Here is a method in php you might not see very often, create_function. This function is similar to anonymous functions in that it can create a function on the fly. We are also adding our first custom rule here.1. Create the function 2. Set the type to function and set the function3. Set the name of 4. Add the rule options 5. Execute rule and valuesthe rule
Preg_match Preg_match is a easy way of validating data based on formats. If you are new to preg_match, I suggest you brush up on your regular expressions. 1. Set the type to preg_match 2. Set the regular expression to check against3. Set the name of the rule 4. Add the rules 5. Check value against rule options
Anonymous Functions Our last check can be accomplished using the anonymous function/closure.1. Create the closure 2. Set the type to ‘closure’ 3. Set the closure3. Set the name of the 4. Add the rule options 5. Check values againstrule rule
Challenge!Perform this optional challenge to better your understanding ofvalidation in ProdigyVIew.1. Create a class with a static method.2. Have that static method accept a check string and check if that string contains the letters ‘pv_’3. Create an anonymous function that takes the value passed to it and checks it against the static method and returns the result.4. Add the anonymous function to the validator, and assign it name.5. Pass in string values to test.
API ReferenceFor a better understanding of Validation in ProdigyView, visitthe api by clicking on the link below.PVValidator More Tutorials For more tutorials, please visit: http://www.prodigyview.com/tutorials www.prodigyview.com