DEPRECATION WARNING
This documentation is not using the current rendering mechanism and is probably outdated. The extension maintainer should switch to the new system. Details on how to use the rendering mechanism can be found here.
Validators¶
A validator is a rule which will be applied on a field after the form submission.
Hint
By convention, every time a new common validator is configured, its configuration should be set at the path config.tx_formz.validators
; this way, it may be used again by different fields.
Properties¶
You can find below the list of parameters usable by a validator.
Property | Title |
---|---|
* className | Class name |
* options | Options |
messages | Messages |
activation | Validator activation |
Class name¶
Property
className
Required?
Yes
Description
Contains the class name used for this validator.
Example:
config.tx_formz.validators.myRule {
className = MyVendor\MyExtension\Validator\MyRuleValidator
}
Validator options¶
Property
options
Required?
Depends of the validator, some options may be mandatory and cause problems if not filled.
Description
Contains the options which will be sent to the validators. These options are predefined in the validator, and must then be known in order to be used correctly.
Example:
config.tx_formz.validators.numberLength {
className = NumberLength
options {
# Minimum size.
minimum = 0
# Maximum size.
maximum = 0
}
}
Note
To know the options of a validator, you must read the documentation of its PHP class (see the chapter “Validator”).
Validator messages¶
Property
messages
Required?
No
Description
Allows to override the messages of the validator. A validator may have one or more messages, and each one is identified by a key, default
being by convention the default key.
Example:
config.tx_formz.validators.numberLength {
messages {
# Two message keys: `default` and `test`.
default {
# Path to the LLL key of the message.
key = validator.form.number_length.error
# Extension containing the LLL file.
extension = formz
}
test {
# If you fill `value`, the value will be directly used
# and the system wont try to fetch a translation.
value = Message test!
}
}
}
Validator activation¶
Property
activation
Required?
No
Description
It is possible to activate a validator only in certain cases. The principle is exactly the same of the fields activation, see “Conditions d'activation” and “Activation du champ”.
Example — activating the rule required
of the field passwordRepeat
only when the field password
is valid:
passwordRepeat {
validation {
required < config.tx_formz.validators.required
required.activation {
items {
passwordIsValid {
type = fieldIsValid
fieldName = password
}
}
condition = passwordIsValid
}
}
}
Use Ajax validation¶
Property
useAjax
Required
No
Description
If this property is defined, an Ajax request is sent by JavaScript when it needs to test this validator.
Note that if a JavaScript version of this validator exists (see “Register a validator”), then filling this property wont have any effect and the JavaScript validator will be used instead of Ajax.
myField {
validation {
serverValidation {
className = MyVendor\MyExtension\Validation\Validator\MyValidator
useAjax = 1
}
}
}