Validators
The form framework ships a set of server-side validators (derived from Extbase validators) which you can use in form elements. Some validators can only be used for certain elements, e.g. the "Date range validator" can only be used for "Date" elements. Some form elements (like "Email") come with validators.
You can define your own validation error messages using the validationErrorMessages
property. These error messages can also be set in the form editor.
Client-side validation
In the form framework, HTML 5-based frontend validation can be added to form elements, but JavaScript validation is not included. The TYPO3 core have no plans to add this functionality at the current time. However, you can add it yourself if required. Examples of reliable and well-maintained projects are Parsley and jQuery Validation.
Localization of client side validation
Display of validation messages is browser-specific and not generated by TYPO3 so these messages cannot easily be changed. However, you can use JavaScript to change validation messages. See Stack Overflow for more information.
Server-side validation
Alphanumeric validator (
Alphanumeric)
The "Alphanumeric validator"
checks for alphanumeric strings. Alphanumeric is defined as a combination of
alphabetic and numeric characters [A-.
Number of submitted values validator (
Count)
The "Number of submitted values validator" checks if a value contains a specific number of elements. The validator has two options:
- Minimum [
options.]: The minimum count to accept.minimum - Maximum [
options.]: The maximum count to accept.maximum
Date range validator (
DateRange )
The "Date range validator" checks if a value is a valid DateTime object and within a specified date range. The range can be defined by providing a minimum and/or maximum date. The validator has two options:
- Format [
options.]: The format of the minimum and maximum option. Default: [format Y-].m- d - Minimum date [
options.]: The minimum date formatted asminimum Y-.m- d - Maximum date [
options.]: The maximum date formatted asmaximum Y-.m- d
The options
minimum and
maximum must have the format 'Y-m-d' which
represents the RFC 3339
'full-date' format.
The input must be a DateTime object. This input can be tested against a minimum date and a maximum date. The minimum date and the maximum date are strings. The minimum and maximum date can be configured through the validator options.
Date/time validator (
DateTime )
The "Date/time validator"
checks if a value is a valid DateTime object. The date string is
expected to be formatted according to the W3C standard
which is YYYY-, for example 2005-.
Email validator (
EmailAddress )
The "Email validator"
checks if a value is a valid email address. The format of a valid email
address is defined in RFC 3696.
This standard allows international characters and multiple
@ signs.
File size validator (
FileSize )
The "File size validator" validates the size of a file resource. The validator has two options:
- Minimum [
options.]: The minimum file size. Use the formatminimum <size>B. For example:|K |M |G 10Mis 10 Megabytes. - Maximum [
options.]: The maximum file size. Use the formatmaximum <size>B. For example:|K |M |G 10Mis 10 Megabytes.
Use the format <size>B for file size, for example, 10M
is 10 megabytes. Note: the maximum file size also depends on the php.
settings of your environment.
Floating-point number validator (
Float)
The "Floating-point number validator"
checks if a value is of type float or a string matching the regular
expression [0-.
Integer number validator (
Integer)
The "Integer number validator" checks if a value is a valid integer.
Empty validator (
NotEmpty )
The "Empty validator" checks if a value is not empty (i.e. equal to NULL, empty string, empty array or empty object).
Number validator (
Number)
The "Number validator" checks if a value is a number.
Number range validator (
NumberRange )
The "Number range validator" checks if a value is a number in a specified range. The validator has two options:
- Minimum [
options.]: The minimum value.minimum - Maximum [
options.]: The maximum value.maximum
Regular expression validator (
RegularExpression )
The "Regular expression validator" checks if a value matches a specified regular expression. Delimiters or modifiers are not supported. The validator has one option:
- Regular expression [
options.]: The regular expression to use for validation, used as given.regular Expression
As an example, a user submits a domain name and the submitted value should only
contain the second and the top level domain, i.e. "typo3.org" instead of
"https://typo3.org". The regular expression for this would be /^.
String length validator (
StringLength )
The "String length validator" checks if a value is a valid string and its length is within a specified range. The validator has two options:
- Minimum [
options.]: The minimum length of a valid string.minimum - Maximum [
options.]: The maximum length of a valid string.maximum
Non-XML text validator (
Text)
The "Non-XML text validator" checks if a value is a valid piece of text (containing no XML tags). This basically means that tags are stripped out. In this special case quotes are not encoded (see filter_var() for more information.
Be aware that the value of this check entirely depends on the output context. The validated text is not expected to be secure. If you want to be sure of that, use a customized regular expression or filter on output.
Translation of validation messages
To learn more about this topic, see here.
Custom validator implementations
Validators belong to configuration prototypes in a validatorsDefinition.
Set the implementationClassName property of the prototype to your
own validator classes.
prototypes:
standard:
validatorsDefinition:
Custom:
implementationClassName: 'VENDOR\MySitePackage\Domain\Validation\CustomValidator'
Add options to your validator and provide a default value yourCustomOption:
prototypes:
standard:
validatorsDefinition:
Custom:
implementationClassName: 'VENDOR\MySitePackage\Domain\Validation\CustomValidator'
options:
yourCustomOption: 'Jurian'
You can override the default value in your form definition:
identifier: sample-form
label: 'Simple Contact Form'
prototype: standard
type: Form
renderables:
-
identifier: subject
label: 'Name'
type: Text
validators:
-
identifier: Custom
options:
yourCustomOption: 'Mathias'
As mentioned above, EXT:form uses Extbase validators. That said,
your own validators should extend
\TYPO3\.
Read more in "TYPO3 Explained":
Custom Extbase validator implementation.