Skip to content

Waldir/PHP-Form-Validation

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 

Repository files navigation

PHP-Form-Validation

PHP Form validation class

A Simple and lightweight PHP validator class that will validate form submitted data

Usage example:

include( Validate.class.php );

// set the rules to sanitize and validate.

$rules = array( 
    'name' => array(
        'required'     => true,
        'alpha_space'  => true,
        'min_length'   => 3,
        'max_length'   => 19 ),

    'id' => array(
        'required'     => true,
        'numeric'      => true,
        'validate_int' => true ) );

// form was submitted.
if ( $_SERVER['REQUEST_METHOD'] === 'POST' )
{
    // Initiate a new validator using the post rules.
    $validator = new Validate( $_POST, $rules );

    // if validation passed return clean data or error.
    if( $validator->validate() )
    {
        $vars = $validator->getFields();
        // code that uses validated fields
    } else {
        $error = $validator->getError();
        // code that uses error messege
    }
}

New rule functins can be easily added by adding the functions to the Validate.class.php file and they can be called by using the same name as the function on the rules array.

About

PHP Form validation class

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages