Recommend this page to a friend! |
Classes of Jorge Castro | PHP Validation One Library | README.md | Download |
|
DownloadValidationOneIt's a PHP library for fetch and validate fields and store messages in different containers(including error, warning, info, and success) depending on the conditions. ExamplesTutorial Form and Table with PHP It is an example of functionality. A normal example is more complex, even if it's only a few lines of code. ValidationOneLet's say we want to validate a value an input value (get) called "id", we could do the next things:
But, where is the error?. It's in messagelist
However, we could also show a message by type (error, warning..) and only message by specific identifier.
Why the messages are store in some structure?. Is it not easy to simply return the error? . The answer is a form. Le't say we have a form with 3 fields. If one of them fails, then the error must be visible for each field separately. Also the whole form could have it's own message. condition ($condition, $message = "", $conditionValue = null, $level = 'error', $key = null)It adds a condition that it depends on the type of the input.
Example:
Input type x Conditions| Input type | Condition | | |----------------------------------------------|--------------------------------------------------------------------|---| | number | gt,lt,gte,lte,between | | | string | minlen,maxlen,betweenlen,contain<br>,notcontain,alpha,alphanum,text,regexp,email,url,domain | | | date | gt,lt,gte,lte,between | | | datestring | gt,lt,gte,lte,between | | | boolean | true,false | | | file | minsize,maxsize,req,image,doc,compression,architecture,ext | | | * (it applies for any type) | req,eq,ne,null,notnull,empty,notempty | | | * | function | | | * | fn.static.Class.methodstatic | | | * | fn.global.function | | | * | fn.object.Class.method where object is a global $object | | | * | fn.class.Class.method | | | * | fn.class.\namespace\Class.method | | Conditions.| Condition | Description | Value Example | |---------------------------------------------------------|--------------------------------------------------------|------------------------| | architecture | The extension of the file must be an architecture file | | | between | The number must be between two values | [0,20] | | betweenlen | The lenght of the text must be between two values | [0,20] | | compression | The extension of the file must be an compression file | | | contain | The text must contain a value | "text" | | doc | The extension of the file must be an document file | | | eq (the value to compare could be an single value or array) | The value must be equals to | "text",["text","text2"] | | exist | The file must exists | | | ext | The extension must be in a list of extensions | ["ext1","ext2","ext3"] | | false | The value must be false (===false) | | | fn.class.\namespace\Class.method | The method of a class must returns true | | | fn.class.Class.method | The method of a class must returns true | | | fn.global.function | The global function must returns true | | | fn.object.Class.method where object is a global $object | The method of a global object must returns true | | | fn.static.Class.methodstatic | The static method of a class must returns true | | | function | The function must returns true | | | gt | The value must be greater than | 123 | | gte | The value must be greater or equal than | 123 | | image | The extension of the file must be an image file | | | lt | The value must be less than | 123 | | lte | The value must be less or equal than | 123 | | maxlen | The maximum lenght of a string | 123 | | maxsize | The maximum size of a file | 123 | | minlen | The minimum lenght of a string | 123 | | minsize | The minimum size of a file | 123 | | mime (the value to compare could be an string or array) | The mime type of a file | "application/msword" or ["application/msword","image/gif"]| | mimetype | The mime type (without subtype) of a file | "application" or ["application,"image"]| | ne (the value to compare could be an single value or array) | The value must not be equals. | 123,[123,345],["aa","bb"] | | notcontain | The value must not contain a value | "text" | | notexist | The file must not exist | | | notnull | The value must not be null | | | null | The value must be null | | | empty | The value must be empty (i.e. "",0,null) | | | notempty | The value must not be empty (i.e. not equals to "",0,null)| | | req | The value must be equal | | | true | The value must be true (===true) | | Examples:
MessageListMessageList is a list of containers of messages. It's aimed for convenience, so it features many methods to access of the information in different ways. Messages are cataloged as follow | id | Description | Example | |---------|----------------------------------------------------------------------|---------------------------------------| | error | The message is an error and it must be solved. It is a show stopper. | Database is down | | warning | The message is a warning that maybe it could be ignored. | The registry was stored but with warnings | | info | The message is an information | Log is stored | | success | The message is a succesful operation | Order Accepted | | Sometimes, both errors are warning are considered as equals. So the system allows to read an error or warning. Error has always the priority, then warning, info and success. If you want to read the first message, then it starts searching for errors. You can obtain a message as an array of objects of the type MessageItem, as an array of string, or as an a single string (first message) Pipeline
version list
todo
NoteIt's distributed as dual license, as lgpl-v3 and commercial. You can use freely in your close source project. However, if you change this library, then the changes must be disclosed. |