PHP Class Habari\FormValidators

Extend this class to supply your own validators, by default we supply most common
Show file Open project: habari/system

Public Methods

Method Description
have ( string $validator ) : boolean Determine if a validator is implemented in this class
validate_email ( string $text, FormControl $control, FormContainer $form, string $warning = null ) : array A validation function that returns an error if the value passed in is not a valid Email Address, as per RFC2822 and RFC2821.
validate_groupname ( $value, FormControl $control, FormContainer $form, string $allowed_name = null, string $warning = null ) : array A validation function that returns an error if the the passed group name is unavailable
validate_range ( string $value, FormControl $control, FormContainer $container, float $min, float $max, string $warning = null ) : array A validation function that returns an error if the value passed is not within a specified range
validate_regex ( string $value, FormControl $control, FormContainer $container, string $regex, string $warning = null ) : array A validation function that returns an error if the value passed does not match the regex specified.
validate_required ( $value, FormControl $control, FormContainer $form, string $warning = null ) : array A validation function that returns an error if the value passed in is not set.
validate_same ( $value, FormControl $control, FormContainer $form, FormControl $matcher, string $warning = null ) : array A validation function that returns an error if the passed control values do not match
validate_url ( string $text, FormControl $control, FormContainer $form, string $warning = null, $schemes = ['http', 'https'], $guess = true ) : array A validation function that returns an error if the value passed in is not a valid URL.
validate_username ( $value, FormControl $control, FormContainer $form, string $allowed_name = null, string $warning = null ) : array A validation function that returns an error if the the passed username is unavailable
validate_wsse ( string $value, FormControl $control, FormContainer $form, string $warning = null ) : array A validation function that returns an error if the form's WSSE values don't pass

Method Details

have() public static method

Determine if a validator is implemented in this class
public static have ( string $validator ) : boolean
$validator string The name of a validator to find
return boolean True if this class implements the specified validator

validate_email() public static method

A validation function that returns an error if the value passed in is not a valid Email Address, as per RFC2822 and RFC2821.
public static validate_email ( string $text, FormControl $control, FormContainer $form, string $warning = null ) : array
$text string A string to test if it is a valid Email Address
$control FormControl The control that defines the value
$form FormContainer The container that holds the control
$warning string An optional error message
return array An empty array if the string is a valid Email Address, or an array with strings describing the errors

validate_groupname() public static method

A validation function that returns an error if the the passed group name is unavailable
public static validate_groupname ( $value, FormControl $control, FormContainer $form, string $allowed_name = null, string $warning = null ) : array
$control FormControl The control that defines the value
$form FormContainer The container that holds the control
$allowed_name string An optional name which overrides the check and is always allowed
$warning string An optional error message
return array An empty array if the value exists, or an array with strings describing the errors

validate_range() public static method

A validation function that returns an error if the value passed is not within a specified range
public static validate_range ( string $value, FormControl $control, FormContainer $container, float $min, float $max, string $warning = null ) : array
$value string A value to test if it is empty
$control FormControl The control that defines the value
$container FormContainer The container that holds the control
$min float The minimum value, inclusive
$max float The maximum value, inclusive
$warning string An optional error message
return array An empty array if the value is value, or an array with strings describing the errors

validate_regex() public static method

A validation function that returns an error if the value passed does not match the regex specified.
public static validate_regex ( string $value, FormControl $control, FormContainer $container, string $regex, string $warning = null ) : array
$value string A value to test if it is empty
$control FormControl The control that defines the value
$container FormContainer The container that holds the control
$regex string The regular expression to test against
$warning string An optional error message
return array An empty array if the value exists, or an array with strings describing the errors

validate_required() public static method

A validation function that returns an error if the value passed in is not set.
public static validate_required ( $value, FormControl $control, FormContainer $form, string $warning = null ) : array
$control FormControl The control that defines the value
$form FormContainer The container that holds the control
$warning string An optional error message
return array An empty array if the value exists, or an array with strings describing the errors

validate_same() public static method

A validation function that returns an error if the passed control values do not match
public static validate_same ( $value, FormControl $control, FormContainer $form, FormControl $matcher, string $warning = null ) : array
$control FormControl The control that defines the value
$form FormContainer The container that holds the control
$matcher FormControl The control which should have a matching value
$warning string An optional error message
return array An empty array if the value exists, or an array with strings describing the errors

validate_url() public static method

A validation function that returns an error if the value passed in is not a valid URL.
public static validate_url ( string $text, FormControl $control, FormContainer $form, string $warning = null, $schemes = ['http', 'https'], $guess = true ) : array
$text string A string to test if it is a valid URL
$control FormControl The control that defines the value
$form FormContainer The container that holds the control
$warning string An optional error message
return array An empty array if the string is a valid URL, or an array with strings describing the errors

validate_username() public static method

A validation function that returns an error if the the passed username is unavailable
public static validate_username ( $value, FormControl $control, FormContainer $form, string $allowed_name = null, string $warning = null ) : array
$control FormControl The control that defines the value
$form FormContainer The container that holds the control
$allowed_name string An optional name which overrides the check and is always allowed
$warning string An optional error message
return array An empty array if the value exists, or an array with strings describing the errors

validate_wsse() public static method

A validation function that returns an error if the form's WSSE values don't pass
public static validate_wsse ( string $value, FormControl $control, FormContainer $form, string $warning = null ) : array
$value string The container's value, not very useful
$control FormControl The container that holds the WSSE controls
$form FormContainer The form that holds the container, probalby the same value
$warning string An optional error message
return array An empty array if the value exists, or an array with strings describing the errors