Validator is the base class of all serverside-validation. It also controls inclusion of clientside-valiation (through Validator.js).
Validators are implemented as an argument to the Form constructor. You create a required fields validator like so. In this case, we’re creating a RequiredFields validator - Validator itself is an abstract class.
$validator = new RequiredFields("Email","FirstName"); return new Form($this, "FormName", $fields, $actions, $validator);
To create your own validator, you need to subclass validator and define two methods:
By default, SilverStripe forms with an attached Validator instance use the custom Validator.js clientside logic. It is quite hard to customize, and might not be appropriate for all use-cases. You can disable integrated clientside validation, and use your own (e.g. jquery.validate).
Disable for all forms (in mysite/_config.php):
Validator::set_javascript_validation_handler('none');
Disable for a specific form:
$myForm->getValidator()->setJavascriptValidationHandler('none');
Please use comments for notes, tips and corrections about the described
functionality.
Use the Silverstripe Forum to
ask questions.