FormValidator
in package
implements
FormInterface, ArrayAccess, Countable, IteratorAggregate
Uses
FormTrait
Form validator class
Tags
Interfaces, Classes, Traits and Enums
- FormInterface
- Form interface class
- ArrayAccess
- Countable
- IteratorAggregate
Table of Contents
- $errors : array<string|int, mixed>
- Form validation errors
- $required : array<string|int, mixed>
- Required fields
- $validators : array<string|int, mixed>
- Form validators
- $values : array<string|int, mixed>
- Form values
- __construct() : mixed
- Constructor
- __get() : mixed
- Get method to return the value of values[$name]
- __isset() : bool
- Return the isset value of values[$name]
- __set() : void
- Set method to set the property to the value of values[$name]
- __unset() : void
- Unset values[$name]
- addValidator() : FormValidator
- Add validator
- addValidators() : FormValidator
- Add validators
- count() : int
- Count of values
- createFromConfig() : FormValidator
- Create form validator from config
- filter() : mixed
- Filter values with the filters
- filterValue() : mixed
- Filter value with the filters
- getError() : mixed
- Get error
- getErrors() : array<string|int, mixed>
- Get errors
- getIterator() : ArrayIterator
- Method to iterate over the form elements
- getValidator() : mixed
- Get validator
- getValidators() : mixed
- Get validators
- getValues() : array<string|int, mixed>
- Get values
- hasErrors() : bool
- Has errors
- hasValidator() : bool
- Has validator
- hasValidators() : bool
- Has validators
- isRequired() : bool
- Is required
- offsetExists() : bool
- ArrayAccess offsetExists
- offsetGet() : mixed
- ArrayAccess offsetGet
- offsetSet() : void
- ArrayAccess offsetSet
- offsetUnset() : void
- ArrayAccess offsetUnset
- removeRequired() : FormValidator
- Remove required
- removeValidator() : FormValidator
- Remove validator
- removeValidators() : FormValidator
- Remove validators
- setRequired() : FormValidator
- Set required
- setValues() : FormValidator
- Set values
- toArray() : array<string|int, mixed>
- Get values
- validate() : bool
- Validate values
- addError() : FormValidator
- Add error
Properties
$errors
Form validation errors
protected
array<string|int, mixed>
$errors
= []
$required
Required fields
protected
array<string|int, mixed>
$required
= []
$validators
Form validators
protected
array<string|int, mixed>
$validators
= []
$values
Form values
protected
array<string|int, mixed>
$values
= []
Methods
__construct()
Constructor
public
__construct([array<string|int, mixed> $validators = null ][, mixed $required = null ][, array<string|int, mixed> $values = null ][, mixed $filters = null ]) : mixed
Instantiate the form validator object
Parameters
- $validators : array<string|int, mixed> = null
- $required : mixed = null
- $values : array<string|int, mixed> = null
- $filters : mixed = null
Return values
mixed —__get()
Get method to return the value of values[$name]
public
__get(string $name) : mixed
Parameters
- $name : string
Return values
mixed —__isset()
Return the isset value of values[$name]
public
__isset(string $name) : bool
Parameters
- $name : string
Return values
bool —__set()
Set method to set the property to the value of values[$name]
public
__set(string $name, mixed $value) : void
Parameters
- $name : string
- $value : mixed
Return values
void —__unset()
Unset values[$name]
public
__unset(string $name) : void
Parameters
- $name : string
Return values
void —addValidator()
Add validator
public
addValidator(string $field, mixed $validator) : FormValidator
Parameters
- $field : string
- $validator : mixed
Return values
FormValidator —addValidators()
Add validators
public
addValidators(array<string|int, mixed> $validators) : FormValidator
Parameters
- $validators : array<string|int, mixed>
Return values
FormValidator —count()
Count of values
public
count() : int
Return values
int —createFromConfig()
Create form validator from config
public
static createFromConfig(array<string|int, mixed>|FormConfig $formConfig[, mixed $required = null ][, array<string|int, mixed> $values = null ][, mixed $filters = null ]) : FormValidator
Parameters
- $formConfig : array<string|int, mixed>|FormConfig
- $required : mixed = null
- $values : array<string|int, mixed> = null
- $filters : mixed = null
Return values
FormValidator —filter()
Filter values with the filters
public
filter([mixed $values = null ]) : mixed
Parameters
- $values : mixed = null
Return values
mixed —filterValue()
Filter value with the filters
public
filterValue(mixed $field) : mixed
Parameters
- $field : mixed
Return values
mixed —getError()
Get error
public
getError(string $field, int $index) : mixed
Parameters
- $field : string
- $index : int
Return values
mixed —getErrors()
Get errors
public
getErrors([string $field = null ]) : array<string|int, mixed>
Parameters
- $field : string = null
Return values
array<string|int, mixed> —getIterator()
Method to iterate over the form elements
public
getIterator() : ArrayIterator
Return values
ArrayIterator —getValidator()
Get validator
public
getValidator(string $field, int $index) : mixed
Parameters
- $field : string
- $index : int
Return values
mixed —getValidators()
Get validators
public
getValidators([string $field = null ]) : mixed
Parameters
- $field : string = null
Return values
mixed —getValues()
Get values
public
getValues() : array<string|int, mixed>
Return values
array<string|int, mixed> —hasErrors()
Has errors
public
hasErrors([string $field = null ]) : bool
Parameters
- $field : string = null
Return values
bool —hasValidator()
Has validator
public
hasValidator(string $field, int $index) : bool
Parameters
- $field : string
- $index : int
Return values
bool —hasValidators()
Has validators
public
hasValidators([string $field = null ]) : bool
Parameters
- $field : string = null
Return values
bool —isRequired()
Is required
public
isRequired(string $field) : bool
Parameters
- $field : string
Return values
bool —offsetExists()
ArrayAccess offsetExists
public
offsetExists(mixed $offset) : bool
Parameters
- $offset : mixed
Return values
bool —offsetGet()
ArrayAccess offsetGet
public
offsetGet(mixed $offset) : mixed
Parameters
- $offset : mixed
Return values
mixed —offsetSet()
ArrayAccess offsetSet
public
offsetSet(mixed $offset, mixed $value) : void
Parameters
- $offset : mixed
- $value : mixed
Return values
void —offsetUnset()
ArrayAccess offsetUnset
public
offsetUnset(mixed $offset) : void
Parameters
- $offset : mixed
Return values
void —removeRequired()
Remove required
public
removeRequired(string $field) : FormValidator
Parameters
- $field : string
Return values
FormValidator —removeValidator()
Remove validator
public
removeValidator(string $field, int $index) : FormValidator
Parameters
- $field : string
- $index : int
Return values
FormValidator —removeValidators()
Remove validators
public
removeValidators([string $field = null ]) : FormValidator
Parameters
- $field : string = null
Return values
FormValidator —setRequired()
Set required
public
setRequired(mixed $required) : FormValidator
Parameters
- $required : mixed
Return values
FormValidator —setValues()
Set values
public
setValues(array<string|int, mixed> $values) : FormValidator
Parameters
- $values : array<string|int, mixed>
Return values
FormValidator —toArray()
Get values
public
toArray() : array<string|int, mixed>
Return values
array<string|int, mixed> —validate()
Validate values
public
validate([mixed $fields = null ]) : bool
Parameters
- $fields : mixed = null
Return values
bool —addError()
Add error
protected
addError(string $field, string $error) : FormValidator
Parameters
- $field : string
- $error : string