Skip to content

Rule validators

Jesús Alonso Abad edited this page Jun 20, 2018 · 5 revisions

Every rule validator should extend FormValidator::AbstractRuleValidator or one of its subclasses.

The default rule validators

  • FormValidator::RuleValidators::Always: An always-pass rule validator. Included mainly for testing purposes.

  • FormValidator::RuleValidators::SingleField: A basic validator for rules that involve a single field (e.g., a mandatory field, a field that should be a positive integer...) Takes two parameters:

    • field_selector: The specification of a field selector (an instance of FormValidator::FieldSelector class). See FieldSelector for details on its specification.
    • value_validators: The specification of an array of field value validators (instances of FormValidator::AbstractFieldValueValidator subclasses). See the page on Field value validators for details on their specification.

    Each field selected by the field selector will have its value validated against every value validator.

  • FormValidator::RuleValidators::RelatedFields: A basic validator for rules that involve a couple of fields, when the value of a slave field depends on the value of a master field (e.g., if field CC has a value, field Subject must have a value too) Takes four parameters:

    • master_field_selector: The specification of a field selector (an instance of FormValidator::FieldSelector class) for the master field. See FieldSelector for details on its specification.
    • master_value_conditions: The specification of an array of field value validators (instances of FormValidator::AbstractFieldValueValidator subclasses). See the page on Field value validators for details on their specification. It's optional; if no conditions are met, every master field applies to the slave (usually because the value of the slave is calculated using the master's value).
    • slave_field_selector: The specification of a field selector (an instance of FormValidator::FieldSelector class) for the slave field. See FieldSelector for details on its specification.
    • slave_value_validators: The specification of an array of field value validators (instances of FormValidator::AbstractFieldValueValidator subclasses). See the page on Field value validators for details on their specification. It's optional, although if no validators are specified, the slave fields just pass.

Clone this wiki locally