Validators
From KnowledgeTree Document Management Made Simple
Validation is a key component of the form machinery. Validators fulfill two roles
- extracting the data that is appropriate for the developer from the widget output
- testing that the data conforms to a standard format.
Validators are much simpler than Widgets in most cases.
Basic Validator Configuration
These configuration options will apply to all different validators.
| item | required | type | description |
|---|---|---|---|
| name | yes | string | the name of the data entry to check. E.g. if you have a widget with name "entity_name", then this value would be "entity_name". |
| test | yes | string | synonym for name |
| output | no | string | if this is present, then the validator will output the value to this value in the "results" array. |
| no_output | no | boolean | (default false) if this is set to "true", then there will be no output. if set to "false" (the default) then the "name" parameter will be used as the default "output" parameter. |
String (ktcore.validators.string)
Probably the most common form of input, strings are used all over the place.
| item | required | type | description |
|---|---|---|---|
| trim | no | boolean | (default true) whether to trim the string before outputting it, or applying any other tests to it. |
| max_length | no | int | (default 254) the maximum length of the string. Defaults to 254 since that's the usual length of a db "char" entry. |
| max_length_warning | no | string | What error message to use if the value is too long. |
| min_length | no | int | (default 0) the shortest acceptable string (used for passwords, etc.) |
| min_length_warning | no | string | What error message to use if the value is too short. |
Entity (ktcore.validators.entity)
Checks that the input was a valid entity reference.
| item | required | type | description |
|---|---|---|---|
| class | yes | string | What class to use for the entity |
| id_method | no | string | (default get) what method to use to get the entity, once the value has been extracted. |
| get_method | no | string | Synonym for id_method. id_method is preferred (since it matches the name used in the widget). |
| multi | no | boolean | Whether to expect an array of values. |
Required (ktcore.validators.required)
Checks that some non-empty value was passed in for the parameter.
Required File (ktcore.validators.requiredfile)
Since files are handled slightly differently by PHP, checks that the uploaded file was non-empty.
Email Address (ktcore.validators.emailaddress)
Checks that the input had the correct format for an email. Note: does not check that the email address exists.
Boolean (ktcore.validators.boolean)
Converts the input to a true/false value.
Password (ktcore.validators.password)
If the password widget was set to ask for a confirmation, check that the two passwords match.
Membership (ktcore.validators.membership)
Check that the values provided for the input are all in the "membership" list.
Fieldset (ktcore.validators.fieldset)
Simple, transparent validator which handles data in "sub" fields.
File (ktcore.validators.file)
Consolidates PHP-style file-uploads to work the same as normal input variables.
Array (ktcore.validators.array)
Extracts an array from the inputs.
del.icio.us
reddit

