FormValidationAdapter extends ClientSideValidationAdapter
FormValidationAdapter Class.
Loads validation rules from a schema and generates client-side rules compatible with the FormValidation JS plugin.
Tags
Table of Contents
$schema | RequestSchemaInterface | |
---|---|---|
$translator | Translator | |
rules() | Generate and return the validation rules for this specific validation adapter. | mixed |
formValidationRulesJson() | Generate FormValidation compatible rules from the specified RequestSchema, as a JSON document. | string|array |
formValidationRulesHtml5() | Generate FormValidation compatible rules from the specified RequestSchema, as HTML5 `data-*` attributes. | array |
transformValidator() | Transform a validator for a particular field into one or more FormValidation rules. | mixed |
html5Attributes() | Transform a validator for a particular field into a string of FormValidation rules as HTML data-* attributes. | mixed |
__construct() | Create a new client-side validator. | mixed |
setSchema() | Set the schema for this validator. | mixed |
setTranslator() | Set the translator for this validator, as a valid MessageTranslator object. | mixed |
rules() | Generate and return the validation rules for this specific validation adapter. | mixed |
Properties
$schema
protected
RequestSchemaInterface
$schema
$translator
protected
Translator
$translator
Methods
rules()
Generate and return the validation rules for this specific validation adapter.
public
rules(
[ $format :
mixed
= 'json' ]
[, $stringEncode :
mixed
= true ]
)
: mixed
This method returns a collection of rules, in the format required by the specified plugin.
Parameters
- $format : mixed = 'json'
The format in which to return the rules. For example, "json" or "html5".
- $stringEncode : mixed = true
In the case of JSON rules, specify whether or not to encode the result as a serialized JSON string.
Return values
mixed —The validation rule collection.
formValidationRulesJson()
Generate FormValidation compatible rules from the specified RequestSchema, as a JSON document.
public
formValidationRulesJson(
[ $encode :
bool
= true ]
)
: string|array
See this as an example of what this function will generate.
Parameters
- $encode : bool = true
Specify whether to return a PHP array, or a JSON-encoded string.
Return values
string|array —Returns either the array of rules, or a JSON-encoded representation of that array.
formValidationRulesHtml5()
Generate FormValidation compatible rules from the specified RequestSchema, as HTML5 `data-*` attributes.
public
formValidationRulesHtml5(
)
: array
See Setting validator options via HTML attributes as an example of what this function will generate.
Return values
array —Returns an array of rules, mapping field names -> string of data-* attributes, separated by spaces.
Example: data-fv-notempty data-fv-notempty-message="The gender is required"
.
transformValidator()
Transform a validator for a particular field into one or more FormValidation rules.
protected
transformValidator(
$fieldName :
string
, $validatorName :
string
, $validator :
string[]
)
: mixed
Parameters
- $fieldName : string
- $validatorName : string
- $validator : string[]
Return values
mixedhtml5Attributes()
Transform a validator for a particular field into a string of FormValidation rules as HTML data-* attributes.
public
html5Attributes(
$validator :
string[]
, $prefix :
string
)
: mixed
Parameters
- $validator : string[]
- $prefix : string
Return values
mixed__construct()
Create a new client-side validator.
public
__construct(
$schema :
RequestSchemaInterface
, $translator :
Translator
)
: mixed
Parameters
- $schema : RequestSchemaInterface
A RequestSchema object, containing the validation rules.
- $translator : Translator
A Translator to be used to translate message ids found in the schema.
Return values
mixedsetSchema()
Set the schema for this validator.
public
setSchema(
$schema :
RequestSchemaInterface
)
: mixed
Parameters
- $schema : RequestSchemaInterface
A RequestSchemaInterface object, containing the validation rules.
Return values
mixedsetTranslator()
Set the translator for this validator, as a valid MessageTranslator object.
public
setTranslator(
$translator :
Translator
)
: mixed
Parameters
- $translator : Translator
A Translator to be used to translate message ids found in the schema.
Return values
mixedrules()
Generate and return the validation rules for this specific validation adapter.
public
abstract rules(
[ $format :
string
= 'json' ]
[, $stringEncode :
bool
= true ]
)
: mixed
This method returns a collection of rules, in the format required by the specified plugin.
Parameters
- $format : string = 'json'
The format in which to return the rules. For example, "json" or "html5".
- $stringEncode : bool = true
In the case of JSON rules, specify whether or not to encode the result as a serialized JSON string.
Return values
mixed —The validation rule collection.