Leaf PHP

Form
in package

Leaf Form ---- Leaf's form validation library

Tags
version
3.0.0
since
1.0.0

Table of Contents

Properties

$errors  : mixed
Validation errors
$messages  : mixed
Validation error messages
$rules  : mixed
Validation rules

Methods

__construct()  : mixed
addError()  : mixed
Add validation error
addErrorMessage()  : mixed
Add validation error message
addMessage()  : mixed
Add validation error message
addRule()  : mixed
Add custom validation rule
errors()  : array<string|int, mixed>
Get validation errors
isEmail()  : bool
message()  : mixed
Alias for addMessage
rule()  : mixed
Alias for addRule
submit()  : mixed
Directly 'submit' a form without having to work with any mark-up
supportedRules()  : array<string|int, mixed>
Get a list of all supported rules.
validate()  : false|array<string|int, mixed>
Validate form data
validateRule()  : bool
Validate a single rule
test()  : bool

Properties

$errors

Validation errors

protected mixed $errors = []

$messages

Validation error messages

protected mixed $messages = ['required' => '{Field} is required', 'email' => '{Field} must be a valid email address', 'alpha' => '{Field} must contain only alphabets and spaces', 'text' => '{Field} must contain only alphabets and spaces', 'string' => '{Field} must contain only alphabets and spaces', 'textonly' => '{Field} must contain only alphabets', 'alphanum' => '{Field} must contain only alphabets and numbers', 'alphadash' => '{Field} must contain only alphabets, numbers, dashes and underscores', 'username' => '{Field} must contain only alphabets, numbers and underscores', 'number' => '{Field} must contain only numbers', 'numeric' => '{Field} must be numeric', 'float' => '{Field} must contain only floating point numbers', 'hardfloat' => '{Field} must contain only floating point numbers', 'date' => '{Field} must be a valid date', 'min' => '{Field} must be at least %s characters long', 'max' => '{Field} must not exceed %s characters', 'between' => '{Field} must be between %s and %s characters long', 'match' => '{Field} must match the %s field', 'matchesvalueof' => '{Field} must match the value of %s', 'contains' => '{Field} must contain %s', 'boolean' => '{Field} must be a boolean', 'truefalse' => '{Field} must be a boolean', 'in' => '{Field} must be one of the following: %s', 'notin' => '{Field} must not be one of the following: %s', 'ip' => '{Field} must be a valid IP address', 'ipv4' => '{Field} must be a valid IPv4 address', 'ipv6' => '{Field} must be a valid IPv6 address', 'url' => '{Field} must be a valid URL', 'domain' => '{Field} must be a valid domain', 'creditcard' => '{Field} must be a valid credit card number', 'phone' => '{Field} must be a valid phone number', 'uuid' => '{Field} must be a valid UUID', 'slug' => '{Field} must be a valid slug', 'json' => '{Field} must be a valid JSON string', 'regex' => '{Field} must match the pattern %s', 'array' => '{field} must be an array']

$rules

Validation rules

protected mixed $rules = ['optional' => '/^.*$/', 'email' => '/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/', 'alpha' => '/^[a-zA-Z\s]+$/', 'text' => '/^[a-zA-Z\s]+$/', 'textonly' => '/^[a-zA-Z]+$/', 'alphanum' => '/^[a-zA-Z0-9\s]+$/', 'alphadash' => '/^[a-zA-Z0-9-_]+$/', 'username' => '/^[a-zA-Z0-9_]+$/', 'number' => '/^[0-9]+$/', 'float' => '/^[0-9]+(\.[0-9]+)$/', 'date' => '/^\d{4}-\d{2}-\d{2}$/', 'min' => '/^.{%s,}$/', 'max' => '/^.{0,%s}$/', 'between' => '/^.{%s,%s}$/', 'match' => '/^%s$/', 'contains' => '/%s/', 'boolean' => '/^(true|false|1|0)$/', 'truefalse' => '/^(true|false)$/', 'ip' => '/^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$/', 'ipv4' => '/^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$/', 'ipv6' => '/^([a-fA-F0-9]{1,4}:){7}[a-fA-F0-9]{1,4}$/', 'url' => '/^(https?|ftp):\/\/(-\.)?([^\s\/?\.#-]+\.?)+(\/[^\s]*)?$/i', 'domain' => '/^([a-z0-9]+(-[a-z0-9]+)*\.)+[a-z]{2,}$/i', 'creditcard' => '/^([0-9]{4}-){3}[0-9]{4}$/', 'phone' => '/^\+?(\d.*){3,}$/', 'uuid' => '/^[a-f\d]{8}(-[a-f\d]{4}){4}[a-f\d]{8}$/i', 'slug' => '/^[a-z0-9]+(-[a-z0-9]+)*$/i', 'json' => '/^[\w\s\-\{\}\[\]\"]+$/', 'regex' => '/%s/']

Methods

__construct()

public __construct() : mixed

addError()

Add validation error

public addError(string $field, string $error) : mixed
Parameters
$field : string

The field that has an error

$error : string

The error message

addErrorMessage()

Add validation error message

public addErrorMessage(string|array<string|int, mixed> $field[, string|null $message = null ]) : mixed
Parameters
$field : string|array<string|int, mixed>

The field to add the message to

$message : string|null = null

The error message if $field is a string

addMessage()

Add validation error message

public addMessage(string|array<string|int, mixed> $field[, string|null $message = null ]) : mixed
Parameters
$field : string|array<string|int, mixed>

The field to add the message to

$message : string|null = null

The error message if $field is a string

addRule()

Add custom validation rule

public addRule(string $name, string|callable $handler[, string|null $message = null ]) : mixed
Parameters
$name : string

The name of the rule

$handler : string|callable

The rule handler

$message : string|null = null

The error message

errors()

Get validation errors

public errors() : array<string|int, mixed>
Return values
array<string|int, mixed>

isEmail()

public isEmail(mixed $value) : bool
Parameters
$value : mixed
Return values
bool

message()

Alias for addMessage

public message(string|array<string|int, mixed> $field[, string|null $message = null ]) : mixed
Parameters
$field : string|array<string|int, mixed>

The field to add the message to

$message : string|null = null

The error message if $field is a string

rule()

Alias for addRule

public rule(string $name, string|callable $handler[, string|null $message = null ]) : mixed
Parameters
$name : string

The name of the rule

$handler : string|callable

The rule handler

$message : string|null = null

The error message

submit()

Directly 'submit' a form without having to work with any mark-up

public submit(string $method, string $action, array<string|int, mixed> $fields) : mixed
Parameters
$method : string
$action : string
$fields : array<string|int, mixed>

supportedRules()

Get a list of all supported rules.

public supportedRules() : array<string|int, mixed>
Return values
array<string|int, mixed>

validate()

Validate form data

public validate(array<string|int, mixed> $dataSource, array<string|int, mixed> $validationSet) : false|array<string|int, mixed>
Parameters
$dataSource : array<string|int, mixed>

The data to validate

$validationSet : array<string|int, mixed>

The rules to validate against

Return values
false|array<string|int, mixed>

Returns false if validation fails, otherwise returns the validated data

validateRule()

Validate a single rule

public validateRule(string|array<string|int, mixed> $rule, mixed $valueToTest[, mixed $fieldName = 'item' ]) : bool
Parameters
$rule : string|array<string|int, mixed>

The rule(s) to validate against

$valueToTest : mixed

The value to validate

$fieldName : mixed = 'item'

The rule parameter

Return values
bool

test()

protected test(mixed $rule, mixed $valueToTest[, mixed $fieldName = 'item' ]) : bool
Parameters
$rule : mixed
$valueToTest : mixed
$fieldName : mixed = 'item'
Return values
bool

        
On this page

Search results