Blesta uses the Input component to perform automatic error checking and error message handling. The way it works is by defining a set of rules and validating input based on those rules. The Input component is a simple, yet powerful way to validate input. As we'll see, input can be formatted prior to validation and/or after validation.
Built-in Rules
The Input component has a set of built in rules. The syntax for invoking these rules is a string or a single dimensional array.
Code Block | ||||
---|---|---|---|---|
| ||||
<?php
...
$rules = array(
'field_1' => array(
'empty' => array(
'rule' => "isEmpty",
'negate' => true,
'message' => "Field 1 may not be empty."
)
),
'field_2' => array(
'valid' => array(
'rule' => array("maxLength",32),
'message' => "Field 2 must be 32 characters or less."
)
)
);
$this->Input->setRules($rules);
?> |
isEmpty
isPassword
isDate
matches
compares
between
minLength
maxLength
betweenLength
PHP Rules
In additional to the built-in Input rules, you can also invoke any PHP function as a rule as well.
Note | ||
---|---|---|
| ||
It's important to note that PHP has a number of language constructs that look like functions but are not. You can not use language constructs as rules. |