PHP Classes

PHP Validaton class: Validate submitted form values according to rules

Recommend this page to a friend!
     
  Info   Example   View files Files   Install with Composer Install with Composer   Download Download   Reputation   Support forum   Blog    
Ratings Unique User Downloads Download Rankings
Not enough user ratingsTotal: 448 All time: 6,199 This week: 660Up
Version License PHP version Categories
php-validation-class 1.0.0GNU General Publi...5.0PHP 5, Validation
Description 

Author

This class can validate submitted form values according to rules.

It takes an array of parameters of rules and the $_POST or $_GET array with the submitted form values and verifies if they satisfy the specified rules.

The class returns a list of invalid form values in case some are invalid.

Currently it can validate values with rules like making the value required, maximum and minimum length, check if it is a number, letters or numbers only, email addresses, and URL.

Picture of Alankar
Name: Alankar <contact>
Classes: 1 package by
Country: India India

Example

<form name="frmTest" id="frmTest" action="" method="POST">
    <input type="text" name="first_name" id="first_name" value = "" />
    <button name="submit" value="Submit" type="submit" >Submit</button>
</form>

<?php
require_once 'validation.php';

$array = array('method' => 'POST',
   
'rules' => array('first_name' => array('required' => true,
                                           
'url' => true)
    ),
   
'messages' => array('first_name' => array('required' => 'Please enter first name')
    )
);
$response = Validation::_initialize($array, $_POST);

// if some error messages are present.
if (!$response['valid']) {
   
// it will give you the array with error messages.
   
echo "<pre>";
   
print_r($response);
} else {
   
// all applied validations are passed. You can deal with your submitted information now.
   
echo "<pre>";
   
print_r($_POST);
}
?>


  Files folder image Files (2)  
File Role Description
Plain text file validation.php Class Validaton class.
Accessible without login Plain text file validation_demo.php Example Demo for PHP validation class

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 Install with Composer
 Version Control Unique User Downloads Download Rankings  
 0%
Total:448
This week:0
All time:6,199
This week:660Up
User Comments (1)
Thats a good and useful class :-)
10 years ago (José Filipe Lopes Santos)
70%StarStarStarStar