jinjie / silverstripe-valitron
Better SilverStripe DataObject Validation With Valitron
Installs: 270
Dependents: 3
Suggesters: 0
Security: 0
Stars: 0
Watchers: 2
Forks: 0
Open Issues: 0
Type:silverstripe-vendormodule
Requires
- silverstripe/framework: ^4
- vlucas/valitron: ^1.4
This package is auto-updated.
Last update: 2024-11-29 04:14:41 UTC
README
A very simple validation that make use of Valitron. Provides a helper that add error messages to form fields.
use SilverStripe\ORM\DataObject; use SwiftDevLabs\Valitron\Helper; class MyDataObject extends DataObject { // Validates DataObject public function validate() { $result = parent::validate(); $v = new \Valitron\Validator([ 'Field1' => $this->Field1, 'Field2' => $this->Field2, ]); // Find more rules at https://github.com/vlucas/valitron $v->rule('required', [ 'Field1', 'Feild2', ]); return Helper::validate($v, $result); } }