PHP Classes

CS form validator: Validate submitted form values in multiple ways

Recommend this page to a friend!
  Info   View files Documentation   View files View files (4)   DownloadInstall with Composer Download .zip   Reputation   Support forum (1)   Blog    
Ratings Unique User Downloads Download Rankings
StarStar 34%Total: 486 All time: 5,906 This week: 455Up
Version License PHP version Categories
cs-form-validator 2.0MIT/X Consortium ...5.3PHP 5, Validation
Description 

Author

This class can validate submitted form values in multiple ways.

It provides several functions that implement different types of validation.

The class can validate an array of submitted form values and return a list of errors for invalid values.

Currently it can validate values as required, minimum and maximum value, file presence and image file type, dates within a data range, allow or disallow a list of specific values, values that must be equal or different to other values, email address, URL, numbers, regular expression pattern, check records of a database, etc..

Picture of Nahid Bin Azhar
  Performance   Level  
Name: Nahid Bin Azhar <contact>
Classes: 23 packages by
Country: United States United States
Age: 33
All time rank: 806110 in United States United States
Week rank: 94 Up8 in United States United States Up
Innovation award
Innovation award
Nominee: 6x

Winner: 2x

Documentation

form-validator

its an easy and handy PHP form validator

How to Use

first you have to set validation rules with input name

$rules=[
'name'=>'required&max:10',
'email'=>'required&email&unique:table,email_field'
];

> Noted: every rules will be separated by '&'

after setting up the rules then you have to validate the inputs

$valid=Validator::validate($input, $rules);

It will validate all of your inputs from your rules.

Check Has Error

If you want to check that all of your input are valid then you have to use Validator::hasErrors()

if($valid->hasErrors()){
	//do something
}

If error occurred then return true

Get All Errors Message

If you want to get all errors then use the method Validator::errorsAll()

this method return all error messages as an array. so you can print all error by this procedure

foreach($valid->errorsAll() as $error){
    echo '<li>'.$error.'</li>';
}

Get Specific Message

If you want to get specific field all message then use it. Validator::getErrors('name')

 foreach($valid->getErrors('email') as $error){
	    echo '<li>'.$error.'</li>';
    }

> Noted: Here all errors messages are stored in the session so you can > display it anywhere of the project

List of all rules

> here after the color ':' are mentioned for parameters of rules

- required - min:number [example: min:10] - max:number [example: max:10] - file - date - date_max:date [example: date_max:10-07-2014] - date_min:date [example: date_min:10-07-2014] - in:comma_separeted_string [example: in:3,4,asia,mango] - not_in:comma_separeted_string [example: not_in:3,4,asia,mango] - image - file_type:comma_separeted_string [example: file_type:jpg,png,bmp] - same:another_input_field [example: same:repassword] - different:another_input_field [example: different:firstName] - email [example: email] - url - numeric - integer - range:from,to [example: range:6,30] - pattern:regular_expression [example: pattern:/[0-9]/] - unique:table,column [example: unique:tbl_users,username] - exist:table,column [example: exist:tbl_users,username]


  Files folder image Files  
File Role Description
Accessible without login Plain text file index.php Test Unit test script
Accessible without login Plain text file LICENSE Data Auxiliary data
Accessible without login Plain text file README.md Doc. Documentation
Plain text file validator.php Class Validx Form Validator

 Version Control Unique User Downloads Download Rankings  
 100%
Total:486
This week:0
All time:5,906
This week:455Up
 User Ratings  
 
 All time
Utility:58%StarStarStar
Consistency:50%StarStarStar
Documentation:-
Examples:-
Tests:-
Videos:-
Overall:34%StarStar
Rank:4195