-
Notifications
You must be signed in to change notification settings - Fork 4
Validation
More validation rules comming soon!
<?php $rule = new Formjack\Rule\NotEmpty($invalidMessage, $negate); ?>
<?php
// ...
$form = new Form('Example', array(
new TextField('full_name', array(
// ...
'rules' => array(
new Formjack\Rule\NotEmpty('Please enter your name.');
)
));
));
Checks whether the given value is empty or not.
-
$invalidMessage (string) (optional)
Message that will describe the validation error.
Default:'' -
$negate (bool) (optional)
Inverse logic.
Default:false
Returns true if the given value is not empty. Returns false otherwise.
NOTE: If $negate is set to true return value will be negated.
<?php $rule = new Formjack\Rule\Email($invalidMessage, $negate); ?>
<?php
// ...
$form = new Form('Example', array(
new EmailField('email', array(
// ...
'rules' => array(
new Formjack\Rule\Email('Please enter your email address.');
)
));
));
Checks if the given value is a valid email address.
-
$invalidMessage (string) (optional)
Message that will describe the validation error.
Default:'' -
$negate (bool) (optional)
Inverse logic.
Default:false
Returns true if the given value is a valid email address. Returns false otherwise.
NOTE: If $negate is set to true return value will be negated.
<?php $rule = new Formjack\Rule\Numeric($invalidMessage, $negate); ?>
<?php
// ...
$form = new Form('Example', array(
new NumberField('age', array(
// ...
'rules' => array(
new Formjack\Rule\Numeric('Given value is not a valid number.');
)
));
));
Checks whether the given value is a valid number.
-
$invalidMessage (string) (optional)
Message that will describe the validation error.
Default:'' -
$negate (bool) (optional)
Inverse logic.
Default:false
Returns true if the given value is a valid number. Returns false otherwise.
NOTE: If $negate is set to true return value will be negated.
<?php $rule = new Formjack\Rule\Length($min, $max, $inclusive, $invalidMessage, $negate); ?>
<?php
// ...
$form = new Form('Example', array(
new PasswordField('password', array(
// ...
'rules' => array(
new Formjack\Rule\Length(6, 15, false, 'Invalid password length.');
)
));
));
Checks whether the length of a given value is within defined range.
-
$min (int|null) (optional)
Min length. Ifnull, validator will not validate min length.
Default:null -
$max (int|null) (optional)
Max length. Ifnull, validator will not validate max length.
Default:null -
$inclusive (bool) (optional)
Allow for the value to me equal tominandmaxvalues.
Default:false -
$invalidMessage (string) (optional)
Message that will describe the validation error.
Default:'' -
$negate (bool) (optional)
Inverse logic.
Default:false
Returns true if the length of a given value is within defined range. Returns false otherwise.
NOTE: If $negate is set to true return value will be negated.
<?php $rule = new Formjack\Rule\CompanyVAT($countryCode, $invalidMessage, $negate); ?>
<?php
// ...
$form = new Form('Example', array(
new TextField('vat_number', array(
// ...
'rules' => array(
new Formjack\Rule\CompanyVAT(Formjack\Rule\CompanyVAT::COUNTRY_HR, 'Given VAT number is not valid.');
)
));
));
Checks whether the given values is a valid company VAT number.
-
$countryCode (string) (required)
Country code. List of avaliable countries can be found here: http://ec.europa.eu/taxation_customs/vies/ -
$invalidMessage (string) (optional)
Message that will describe the validation error.
Default:'' -
$negate (bool) (optional)
Inverse logic.
Default:false
Returns true if the given value is a valid company VAT number. Returns false otherwise.
NOTE: If $negate is set to true return value will be negated.
<?php $rule = new Formjack\Rule\Checked($invalidMessage, $negate); ?>
<?php
// ...
$form = new Form('Example', array(
new CheckboxField('legal', array(
// ...
'rules' => array(
new Formjack\Rule\Checked('You muse agree with the given terms.');
)
));
));
Checks whether the checkbox is checked or not.
-
$invalidMessage (string) (optional)
Message that will describe the validation error.
Default:'' -
$negate (bool) (optional)
Inverse logic.
Default:false
Returns true if the checkbox is checked. Returns false otherwise.
NOTE: If $negate is set to true return value will be negated.
<?php $rule = new Formjack\Rule\When($condition, $rules); ?>
<?php
// ...
$form = new Form('Example', array(
new CountrySelectField('country', array(
/* ... */
)),
new StateSelectField('state', array(
// ...
'rules' => array(
new Formjack\Rule\When(function($data){
return ($data['country'] == 'US');
}, array(
new NotEmpty('You must choose a state.')
));
)
));
));
Conditional validation rule.
-
$condition(array $data) (callable) (required)
Callable function that returns a boolean value. If return value is equal totruerules defined within the second parameter will be taken into account during the validation process. If return value is equal tofalserules defined within the second parameter won't be taken into account during the validation process. Formjack will pass a$dataparameter to each callable$conditionso that you can access field values from within the function. -
$rules (array) (optional)
Array of rules that will be used in the validation process if the callable$conditionreturnstrue.
Default:array()