HOW TO add your own validation type?

Discuss everything related to DataValidator. All versions. Any questions related to the DataValidator developing or using should be posted to this forum.

Moderators: ne_moj, zewa, goas

HOW TO add your own validation type?

Postby goas on Nov 30th, '12, 14:25

In order to make your own validation type you have to perform following steps:

1. Create a class SomeNameValidationType in folder /lib/types/. It's constructor should look aproximately like this:
Code: Select all
// no subtype is needed
public function __construct($name, $userFriendlyName = '') {
     parent::__construct($name, '', $userFriendlyName);
}

If you want a subtype to be used, then a constructor is to look as follows:
Code: Select all
// with subtype
public function __construct($name, $subtype, $userFriendlyName = '') {
     parent::__construct($name, $subtype, $userFriendlyName);
}

The parameters, passes to a constructor are:
$name - the name of field to validate
$userFriendlyName (optional) - a name suitable for error reports.

2. If you want the type to maintain the confirming value or field option, then it should extend class ValidatorAnyConfirmingType, else your type should extend class ValidatorAnyType. In either cases new class should also implement interface ValidatorType.

3. Since you have implemented an interface, your classes should contain two methods: method Validate() and method ToString().
Validate() is intended to actually run the validation.
ToString() returns a current validation type description, it is useful for testing and error logging.

Your validator type is ready now to work.
goas
Newbie
Newbie
 
Posts: 9
Joined: Apr 23rd, '12, 11:26

Re: HOW TO add your own validation type?

Postby joy9393 on Oct 24th, '14, 12:51

Since you have implemented an interface, your classes should contain two methods: method Validate() and method ToString().
Validate() is intended to actually run the validation.
ToString() returns a current validation type description, it is useful for testing and error logging.
Are you worried about HP2-Z30 questions exam prep and IFPUG
joy9393
Newbie
Newbie
 
Posts: 1
Joined: Oct 24th, '14, 12:49

Re: HOW TO add your own validation type?

Postby administrator on Oct 26th, '14, 19:35

Thanks, we'll check this issue.
User avatar
administrator
Site Admin
Site Admin
 
Posts: 5841
Joined: Jan 7th, '09, 23:18


Return to ApPHP DataValidator

Who is online

Users browsing this forum: No registered users and 1 guest

cron