This is a simple PHP library for easy form validation.
- Clone the repository or download the ZIP file.
git clone https://github.com/xentixar/easy_php_form_validation.git
- Configure database in database.php inside config directory.
private $database_name = 'your_database_name';
- Include autoload.php file in your file
require_once './autoload.php';
- 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);
- 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'
]);
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.
Check the examples directory for sample usage of the form validation library.
- 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.
This project is licensed under the MIT License - see the LICENSE file for details.