Handles custom validation on fields. Allows for specific, defined validators by FormIt, or custom Validators
that are MODX Snippets.



__construct(
\FormIt $formit, array $config
=
array
)
:
\fiValidatorThe constructor for the fiValidator class
Parameters
| Name |
Type |
Description |
| $formit |
\FormIt |
&$formit A reference to the FormIt class instance.
|
| $config |
array |
Optional. An array of configuration parameters. |
Returns



_getErrorMessage(
string $field, string $parameter, string $lexiconKey, array $properties
=
array
)
:
null|stringCheck for a custom error message, otherwise use a lexicon entry.
Parameters
| Name |
Type |
Description |
| $field |
string |
|
| $parameter |
string |
|
| $lexiconKey |
string |
|
| $properties |
array |
|
Returns
| Type |
Description |
| nullstring |
|



_validate(
string $k, string $v, array $fieldValidators
=
array
)
:
voidHelper method for validating fields
Parameters
| Name |
Type |
Description |
| $k |
string |
|
| $v |
string |
|
| $fieldValidators |
array |
|



addError(
string $key, string $value
)
:
stringAdds an error to the stack.
Parameters
| Name |
Type |
Description |
| $key |
string |
The field to add the error to. |
| $value |
string |
The error message. |
Returns
Details
- access
- private



allowTags(
string $key, string $value, string $allowedTags
)
:
booleanStrip all tags in the field. The parameter can be a string of allowed
tags.
Parameters
| Name |
Type |
Description |
| $key |
string |
The name of the field |
| $value |
string |
The value of the field |
| $allowedTags |
string |
A comma-separated list of tags to allow in the field's value. Leave blank to allow all.
|
Returns



blank(
string $key, string $value
)
:
booleanChecks to see if field is blank.
Parameters
| Name |
Type |
Description |
| $key |
string |
The name of the field |
| $value |
string |
The value of the field |
Returns



contains(
string $key, string $value, string $expr
)
:
booleanSee if field contains a certain value.
Parameters
| Name |
Type |
Description |
| $key |
string |
The name of the field |
| $value |
string |
The value of the field |
| $expr |
string |
The regular expression to check against the field |
Returns



email(
string $key, string $value
)
:
booleanChecks to see if field value is an actual email address.
Parameters
| Name |
Type |
Description |
| $key |
string |
The name of the field |
| $value |
string |
The value of the field |
Returns



isDate(
string $key, string $value, string $format
=
%m/%d/%Y
)
:
booleanChecks to see if the field is a valid date. Allows for date formatting as
well.
Parameters
| Name |
Type |
Description |
| $key |
string |
The name of the field |
| $value |
string |
The value of the field |
| $format |
string |
The format of the date |
Returns



isNumber(
string $key, string $value
)
:
booleanChecks to see if the field is a number.
Parameters
| Name |
Type |
Description |
| $key |
string |
The name of the field |
| $value |
string |
The value of the field |
Returns



islowercase(
string $key, string $value
)
:
booleanChecks to see if a string is all lowercase
Parameters
| Name |
Type |
Description |
| $key |
string |
The name of the field |
| $value |
string |
The value of the field |
Returns



isuppercase(
string $key, string $value
)
:
booleanChecks to see if a string is all uppercase
Parameters
| Name |
Type |
Description |
| $key |
string |
The name of the field |
| $value |
string |
The value of the field |
Returns



maxLength(
string $key, string $value, int $param
=
999
)
:
booleanChecks to see if field value is longer than $param.
Parameters
| Name |
Type |
Description |
| $key |
string |
The name of the field |
| $value |
string |
The value of the field |
| $param |
int |
The maximum length the field can be |
Returns



maxValue(
string $key, string $value, int $param
=
0
)
:
booleanChecks to see if field value is greater than $param.
Parameters
| Name |
Type |
Description |
| $key |
string |
The name of the field |
| $value |
string |
The value of the field |
| $param |
int |
The maximum value the field can be |
Returns



minLength(
string $key, string $value, int $param
=
0
)
:
booleanChecks to see if field value is shorter than $param.
Parameters
| Name |
Type |
Description |
| $key |
string |
The name of the field |
| $value |
string |
The value of the field |
| $param |
int |
The minimum length the field can be |
Returns



minValue(
string $key, string $value, int $param
=
0
)
:
booleanChecks to see if field value is less than $param.
Parameters
| Name |
Type |
Description |
| $key |
string |
The name of the field |
| $value |
string |
The value of the field |
| $param |
int |
The minimum value the field can be |
Returns



password_confirm(
string $key, string $value, string $param
=
password_confirm
)
:
booleanChecks to see if passwords match.
Parameters
| Name |
Type |
Description |
| $key |
string |
The name of the field |
| $value |
string |
The value of the field |
| $param |
string |
The parameter passed into the validator that contains the field to check the password against |
Returns



range(
string $key, string $value, string $ranges
=
0-1
)
:
booleanValidates value between a range, specified by min-max.
Parameters
| Name |
Type |
Description |
| $key |
string |
The name of the field |
| $value |
string |
The value of the field |
| $ranges |
string |
The range the value should reside in |
Returns



regexp(
string $key, string $value, string $expression
)
:
boolean
Parameters
| Name |
Type |
Description |
| $key |
string |
The name of the field |
| $value |
string |
The value of the field |
| $expression |
string |
The regexp to use |
Returns



required(
string $key, string $value
)
:
booleanChecks to see if field is required.
Parameters
| Name |
Type |
Description |
| $key |
string |
The name of the field |
| $value |
string |
The value of the field |
Returns



strip(
string $key, string $value, string $param
)
:
booleanStrip a string from the value.
Parameters
| Name |
Type |
Description |
| $key |
string |
The name of the field |
| $value |
string |
The value of the field |
| $param |
string |
The value to strip from the field |
Returns



stripTags(
string $key, string $value, string $allowedTags
)
:
booleanStrip all tags in the field. The parameter can be a string of allowed
tags.
Parameters
| Name |
Type |
Description |
| $key |
string |
The name of the field |
| $value |
string |
The value of the field |
| $allowedTags |
string |
A comma-separated list of tags to allow in the field's value
|
Returns



validate(
string $key, mixed $value, string $type
)
:
booleanValidates a field based on a custom rule, if specified
Parameters
| Name |
Type |
Description |
| $key |
string |
The key of the field |
| $value |
mixed |
The value of the field |
| $type |
string |
Optional. The type of the validator to apply. Can either be a method name of fiValidator or a Snippet name. |
Returns
Details
- access
- public



validateFields(
\fiDictionary $dictionary, string $validationFields
)
:
arrayValidates an array of fields. Returns the field names and values, with
the field names stripped of their validators.
The key names can be in this format:
name:validator=param:anotherValidator:oneMoreValidator=param
Parameters
| Name |
Type |
Description |
| $dictionary |
\fiDictionary |
|
| $validationFields |
string |
|
Returns
Details
- access
- public