Recommend this page to a friend! |
Download |
Info | Example | Files | Install with Composer | Download | Reputation | Support forum | Blog | Links |
Ratings | Unique User Downloads | Download Rankings | ||||
Not yet rated by the users | Total: 129 | All time: 9,370 This week: 673 |
Version | License | PHP version | Categories | |||
validationone 1.0.1 | GNU Lesser Genera... | 5 | HTTP, PHP 5, Validation |
Description | Author | |
This package can fetch and validate forms and request values. |
<form method="post" enctype="multipart/form-data"> |
It'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.
Tutorial 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.
Let's say we want to validate a value an input value (get) called "id", we could do the next things:
$val=new ValidationOne();
$r = $val->def('ERROR')
->type('integer')
->ifMissingThenDefault()
->condition("eq", "It's not equals to 10", 10)
->condition("eq", "It's not equals to 30 (info)", 30, 'info')
->ifFailThenDefault()
->get('id'); // <-- end of the chain
But, where is the error?. It's in messagelist
var_dump($val->messagelist->allArray()) // here we show all messages of any kind of type.
However, we could also show a message by type (error, warning..) and only message by specific identifier.
var_dump($val->messageList->get('id')->allErrorOrWarning())) // All error or warning contained in the key "id".
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.
It adds a condition that it depends on the type of the input.
@param string $condition
<b>number</b>:req,eq,ne,gt,lt,gte,lte,between,null,notnull<br> <b>string</b>:req,eq,ne,minlen,maxlen,betweenlen,null,notnull,contain,notcontain ,alpha,alphanum,text,regexp,email,url,domain<br> <b>date</b>:req,eq,ne,gt,lt,gte,lte,between<br> <b>datestring</b>:req,eq,ne,gt,lt,gte,lte,between<br> <b>boolean</b>:req,eq,ne,true,false<br> <b>file</b>:minsize,maxsize,req,image,doc,compression,architecture,ext<br> <b>function:</b><br> fn.static.Class.methodstatic<br> fn.global.function<br> fn.object.Class.method where object is a global $object<br> fn.class.Class.method<br> fn.class.\namespace\Class.method<br>
@param string $message
Message could uses the next variables '%field','%realfield','%value','%comp','%first','%second'
Example:
$validation->def(null)
->type('integer')
->condition('eq','%field %value is not equal to %comp ',50)
->condition('eq','%field %value is not equal to %comp ',60)
->set('aaa','variable2');
| 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 | |
| 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:
$validation->def(null)
->type('integer')
->condition('eq','%field %value is not equal to %comp ',50)
->condition('between','%field %value must be between 1 and 50 ',[1,50])
->condition('eq','%field %value is not equal to %comp ',60)
->condition('eq','%field %value is not equal to %comp ',[60,200]) // eq allows a single or array
->condition('fn.static.Example.customval','la funcion no funciona')
->condition('req')
->condition('lt',"es muy grande",2000,'warning')
->condition('eq','%field %value is not equal to %comp',50)
->condition('fn.static.Example.fnstatic','la funcion estatica no funciona')
->condition('fn.static.\somespace\Someclass.methodStatic',null)
->condition('fn.global.customval','la funcion global no funciona')
->condition('fn.object.example.fnnostatic','la funcion object no funciona')
->condition('fn.class.\somespace\Someclass.method','la funcion someclass no funciona')
->condition('fn.class.Example.fnnostatic','la funcion class no funciona');
// ->condition('fn.static.Example.customval','la funcion no funciona')
function customval($value,$compareValue) {
return true;
}
MessageList 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)
It'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.
Files (28) |
File | Role | Description | ||
---|---|---|---|---|
examples (15 files, 1 directory) | ||||
lib (5 files) | ||||
tests (2 files) | ||||
.travis.yml | Data | Auxiliary data | ||
composer.json | Data | Auxiliary data | ||
LICENSE | Lic. | License text | ||
phpunit.xml | Data | Auxiliary data | ||
README.md | Doc. | Documentation |
Files (28) | / | examples |
File | Role | Description | ||
---|---|---|---|---|
docs (1 file) | ||||
benchmarkglobal.php | Aux. | Auxiliary script | ||
common.php | Example | Example script | ||
examplefile.php | Example | Example script | ||
Someclass.php | Class | Class source | ||
testarrayget.php | Class | Class source | ||
testarrayget2.php | Example | Example script | ||
testarrayset.php | Example | Example script | ||
testContinueOnError.php | Example | Example script | ||
testdate.php | Example | Example script | ||
testfetch.php | Class | Class source | ||
testfetchsimple.php | Example | Example script | ||
testglobal.php | Aux. | Auxiliary script | ||
testval1.php | Class | Class source | ||
testval2.php | Class | Class source | ||
validaimage.php | Class | Class source |
Files (28) | / | lib |
File | Role | Description |
---|---|---|
MessageItem.php | Class | Class source |
MessageList.php | Class | Class source |
ValidationInputOne.php | Class | Class source |
ValidationItem.php | Class | Class source |
ValidationOne.php | Class | Class source |
Files (28) | / | tests |
File | Role | Description |
---|---|---|
bootstrap.php | Example | Example script |
ValidationOneTest.php | Class | Class source |
The PHP Classes site has supported package installation using the Composer tool since 2013, as you may verify by reading this instructions page. |
Install with Composer |
Version Control | Unique User Downloads | Download Rankings | |||||||||||||||
100% |
|
|
Applications that use this package |
If you know an application of this package, send a message to the author to add a link here.