Skip to content

xentixar/easy_php_form_validation

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Easy PHP Form Validation

This is a simple PHP library for easy form validation.

Table of Contents

Installation

  1. Clone the repository or download the ZIP file.
git clone https://github.com/xentixar/easy_php_form_validation.git
  1. Configure database in database.php inside config directory.
private $database_name = 'your_database_name';
  1. Include autoload.php file in your file
require_once './autoload.php';

Usage

  1. Create an instance of the Validation class and pass data to it.
$data = [
    'name' => 'John',
    'email' => 'test@gmail.com',
    'password' => '12345678',
    'role' => 'user'
];
$validator = new Validation($data);
  1. Add validation rules using the validate method.
$validated = $validator->validate([
    'name' => 'required|max:100',
    'email' => 'required|email|max:100|exists:users,email',
    'password' => 'required|min:8|max:25',
    'role' => 'required|in:admin,user'
]);

Validation Rules

The library supports the following validation rules:

  • 'required' => Field must be present in the form data.
  • 'email' => Field must be a valid email address.
  • 'number' => Field must be a number.
  • 'image' => Field must be a valid email image.
  • 'max:m' => Maximum length for strings or maximum value for numbers.
  • 'min:n' => Minimum length for strings or minimum value for numbers.
  • 'in:something,something_else' => Field must be a value present in the data.
  • 'alpha_dash' => Field can only contain alpha-numeric, underscores and dashes.
  • 'exists:table,column' => Field must be a value present in the column of the given table.
  • 'unique:table,column' => Field must be a unique value in the column of the given table.
  • 'unique:table,column,id' => Field must be a unique value in the column of the given table except given id.

Examples

Check the examples directory for sample usage of the form validation library.

Contributing

  • Fork the repository.
  • Create a new branch: git checkout -b feature-name.
  • Commit your changes: git commit -m 'Add new feature'.
  • Push to the branch: git push origin feature-name.
  • Submit a pull request.

License

This project is licensed under the MIT License - see the LICENSE file for details.

About

Easy form validation in PHP.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages