{"id":33988495,"url":"https://github.com/tamedevelopers/validator","last_synced_at":"2026-01-11T10:45:33.633Z","repository":{"id":40605663,"uuid":"507735623","full_name":"tamedevelopers/validator","owner":"tamedevelopers","description":"PHP Form Validator is a small no-dependency library for php form validation.","archived":false,"fork":false,"pushed_at":"2025-09-18T08:32:47.000Z","size":683,"stargazers_count":4,"open_issues_count":0,"forks_count":1,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-09-18T10:26:56.394Z","etag":null,"topics":["composer","form-validator","laravel","php","php-form-validotor","php-library","phpform"],"latest_commit_sha":null,"homepage":"","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/tamedevelopers.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2022-06-27T02:17:03.000Z","updated_at":"2025-09-18T08:31:25.000Z","dependencies_parsed_at":"2023-07-17T01:39:43.060Z","dependency_job_id":"c95ea9ca-cfc7-4019-b01a-8bb55fe160c5","html_url":"https://github.com/tamedevelopers/validator","commit_stats":null,"previous_names":["tamedevelopers/validator"],"tags_count":56,"template":false,"template_full_name":null,"purl":"pkg:github/tamedevelopers/validator","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tamedevelopers%2Fvalidator","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tamedevelopers%2Fvalidator/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tamedevelopers%2Fvalidator/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tamedevelopers%2Fvalidator/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/tamedevelopers","download_url":"https://codeload.github.com/tamedevelopers/validator/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tamedevelopers%2Fvalidator/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":27701248,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-12-13T02:00:09.769Z","response_time":147,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["composer","form-validator","laravel","php","php-form-validotor","php-library","phpform"],"created_at":"2025-12-13T05:57:26.801Z","updated_at":"2025-12-13T05:57:27.457Z","avatar_url":"https://github.com/tamedevelopers.png","language":"PHP","funding_links":["https://www.buymeacoffee.com/tamedevelopers"],"categories":[],"sub_categories":[],"readme":"# PHP Form Validator  - PFV\n\n[![Total Downloads](https://poser.pugx.org/tamedevelopers/validator/downloads)](https://packagist.org/packages/tamedevelopers/validator)\n[![Latest Stable Version](https://poser.pugx.org/tamedevelopers/validator/version)](https://packagist.org/packages/tamedevelopers/validator)\n[![License](https://poser.pugx.org/tamedevelopers/validator/license)](https://packagist.org/packages/tamedevelopers/validator)\n[![Code Coverage](https://codecov.io/github/tamedevelopers/validator/graph/badge.svg?token=3VCGHQZH43)](https://codecov.io/github/tamedevelopers/validator)\n\n## Documentation\n\n* [Requirements](#requirements)\n* [Installation](#installation)\n* [Instantiate](#instantiate)\n* [Laravel Support](#laravel-support)\n* [Methods That Should Always Come First](#methods-that-should-always-come-first)\n* [Global Configuration](#methods-that-should-always-come-first)\n* [Csrf](#csrf)\n    * [Csrf Form Input](#csrf-form-input)\n    * [Csrf Token](#csrf-token)\n* [Usage](#usage)\n  * [Error Type](#error-type)\n  * [Token](#token)\n  * [POST](#post)\n  * [GET](#get)\n  * [ALL](#all)\n  * [ANY](#any)\n  * [Rules](#rules)\n  * [Validate](#validate)\n  * [Save](#save)\n  * [Data Types](#data-types)\n  * [Operators](#operators)\n  * [noInterface](#nointerface)\n  * [Before](#before)\n  * [After](#after)\n  * [Has Error](#has-error)\n  * [Is Validated](#is-validated)\n* [Reset Error](#reset-error)\n* [Only](#only)\n* [Except](#except)\n* [Has](#has)\n* [Old](#old)\n* [Merge](#merge)\n* [Only Data](#only-data)\n* [Except Data](#except-data)\n* [GetForm](#getForm)\n* [Get Message and Class](#get-message-and-class)\n* [Collection](#collection)\n* [Collection Methods](#collection-methods)\n* [toObject](#toobject)\n* [toArray](#toarray)\n* [toJson](#tojson)\n* [Helpers](#helpers)\n* [Useful links](#useful-links)\n\n## Requirements\n\n- `\u003e= php 8.0+`\n\n## Installation\n\nPrior to installing `validator package` get the [Composer](https://getcomposer.org) dependency manager for PHP because it'll simplify installation.\n\n```txt\ncomposer require tamedevelopers/validator\n```\n\n## Instantiate — `Instantiate class using`\n- It's helper class can be called, using -- `form()`\n\n```php\nrequire_once __DIR__ . '/vendor/autoload.php';\n\nuse \\Tamedevelopers\\Validator\\Validator;\n\n$form = new Validator();\n```\n\n## Laravel Support\n- Now supports Laravel and with same Functionalities no different\n    - `use Tamedevelopers\\Validator\\Validator;`\n\n```php\npublic function save(Request $request){\n\n    $form = new Validator();\n    or\n    $form = form();\n}\n```\n\n## Methods That Should Always Come First\n- All are Optional `method`\n    - These methods are only mandatory on usage and should always come first before others.\n\n| Methods       |        Description                                                        |\n|---------------|---------------------------------------------------------------------------|\n| -\u003eerrorType() |  `bool` to format error's on display: `single or multiple`                |\n| -\u003etoken()     |  `bool` to Enable or Disable `csrf_token` for each request                |\n| -\u003epost()      |  Convert Form request to `POST` only                                      |\n| -\u003eget()       |  Convert Form request to  `GET` only                                      |\n| -\u003eall()       |  Convert Form request to `any`                                            |\n\n```php\n$form-\u003epost()-\u003erules([\n    // \n]);\n```\n\n## Global Configuration\n- It's helper class can be called, using -- `config_form()`\n\n| Keys          |        Description                      |\n|-------------|-----------------------------------------|\n| request     |  String `POST\\|GET\\|ALL` Default `POST` |\n| error_type  |  Boolean `true\\|false` Default `false`  |\n| csrf_token  |  Boolean `true\\|false` Default `true`   |\n| class       |  Assoc Array `error\\|success` error class type to be returned on both success and failure   |\n\n```php\nconfig_form(\n    request       : 'POST',\n    error_type    : true,\n    csrf_token    : true,\n    class         : [\n        'error'     =\u003e 'alert alert-danger',\n        'success'   =\u003e 'alert alert-success'\n    ]\n); \n```\n\n## Csrf\n- Implementing `Csrf` (Cross-Site Request Forgery)\n    - By default the form requires all request to have a token attached.\n        - You can disable the usage with the `config_form()` Helper\n\n\n### Csrf Form Input\n- This will create html input element with valid `csrf token`\n    - It's a function and you don't need to `echo`\n        - Use anywhere inside your HTML form\n\n```html\ncsrf();\n\n\u003cinput type=\"hidden\" name=\"_token\" value=\"efef4c9360f26848f0d102b478e51859cfce4c9b197eb9d6473abfcaa2c6da38\"\u003e\n```\n![Sample Csrf Form Input](https://raw.githubusercontent.com/tamedevelopers/validator/main/getErrorMessage.png)\n\n### Csrf Token\n- This will return the `csrf token` string\n\n```php\ncsrf_token();\n```\n\n## USAGE\n- All Methods of usage \n\n\n### Error Type\n- Takes a param as `bool` Default is `false`\n    - You can call separately or Call Before any other method, if intend to use.\n\n| Error |        Description            |\n|-------|-------------------------------|\n| false |  `Default` Errors displayed one after another  |\n| true  |  This allow all errors to be displayed once, `as an array` |\n\n```php\n$form-\u003eerrorType(false);\n```\n\n### Token\n- Takes a param as `bool` Default is `false`\n    - Allow disability of `csrf_token` on each form request\n\n| Error |        Description                            |\n|-------|-----------------------------------------------|\n| false |  `Default` Will disable `csrf_token` usage    |\n| true  |  This allow `csrf_token` per request only     |\n\n```php\n$form-\u003etoken(false);\n```\n\n### POST\n- Set the Form Request to `POST`\n    - This will always override the `config_form()` settings\n\n```php\n$form-\u003epost();\n```\n\n### GET\n- Set the Form Request to `GET`\n\n```php\n$form-\u003eget();\n```\n\n### All\n- Will automatically detect if request type is `GET\\|POST` and get it's data.\n\n```php\n$form-\u003eall()-\u003erules([\n    // \n])\n```\n\n### Any\n- same as `all`\n\n```php\n$form-\u003eany()-\u003erules([\n    // \n])\n```\n\n### Rules\n- By default only `DATA TYPE` and `[INPUT_NAME]` is required\n    - Always seperate each indicator with a 'colon' `:` or 'pipe' `|`\n\n| DATA TYPE |  INPUT_NAME  | COMPARISON OPERATOR | VALUE TO COMPARE |\n|-----------|--------------|---------------------|------------------|\n| string    | : country    | :  ==               | : 0              |\n| email     | : email      | :                   |                  |\n\n```php\n$form-\u003erules([\n    \"string|country|==|0\"   =\u003e 'Please Select a Country',\n    \"email:email\"           =\u003e 'Please enter a valid email address',\n])\n```\n\n- HTML FORM Structure\n```html\n\u003cform\u003e\n    \u003cselect name=\"country\"\u003e\n        \u003coption value=\"0\"\u003eSelect Country\u003c/option\u003e\n        \u003coption value=\"NGA\"\u003eNigeria\u003c/option\u003e\n        \u003coption value=\"USA\"\u003eUnited States of America\u003c/option\u003e\n    \u003c/select\u003e\n\n    \u003cinput type=\"hidden\" name=\"_token\" value=\"749c345a1d407f29e777349f5e46a8d6d2cd51454b6719228b5ee28f94c30432\"\u003e\n    \u003cinput type=\"email\" name=\"email\" placeholder=\"Email Address\"\u003e\n\u003c/form\u003e\n```\n\n### Validate\n- Takes an [optional] `closure` function as the param\n\n```php\n$form-\u003erules([\n    \"s:name\" =\u003e 'Please enter a name',\n])-\u003evalidate(function($response){\n\n    $response-\u003eparam; //Collection of form data\n    $response-\u003egetMessage(); //message property\n});\n```\n\n### Save\n- Expects a `closure` function as the param\n    - Message property will be empty string on success `$response-\u003emessage`\n\n```php\n$form-\u003erules([\n    \"s:name\" =\u003e 'Please enter a name',\n])-\u003esave(function(){\n    //on success\n});\n```\n\n### Data Types\n- `Supports 9 Data Flags type`\n\n| Data types | abbr |          Description          |\n|------------|------|-------------------------------|\n| email      |  e   |  `Email` data validation      |\n| bool       |  b   |  `Boolean` data validation    |\n| string     |  s   |  `String` data validation     |\n| html       |  -   |  `html` CMS/Blog content validation |\n| dev        |  -   |  `dev` CMS/Blog/Dev like content  validation |\n| raw        |  -   |  `raw` Collect content without validation |\n| str_len    |  sl  |  `String Length` validation   |\n| enum       |  en  |  `Enum` Forms `checkbox \\| radio` or any form data that normally has no value when not checked |\n| array      |  a   |  `Array` data validation      |\n| float      |  f   |  `Float` data validation      |\n| int        |  i   |  `Int` data validation        |\n| url        |  u   |  `Url` data validation        |\n\n\n### Operators\n- `Supports 10 operational statement`\n\n| sign |          Description          |\n|------|-------------------------------|\n| ==   |  Equal to                     |\n| ===  |  Strictly Equal to            |\n| !=   |  Not Equal To                 |\n| !==  |  Not Strictly Equal To        |\n| \u003e    |  Greater than                 |\n| \u003e=   |  Greater than or Equal to     |\n| \u003c    |  Less than                    |\n| \u003c=   |  Less than or Equal to        |\n| \u003c or \u003e |  Less than or Greater than    |\n| \u003c and \u003e|  Less than and Greater than   |\n\n\n### noInterface\n- Expects a `closure` function as the param\n    - have access to form data without any validation\n\n```php\n$form-\u003enoInterface(function($response){\n\n    if($response-\u003ehas('amount')){\n        // exec code\n    }\n});\n```\n\n### Before\n- Expects a `closure` function as the param\n    - Will only execute code within when Request is [GET]\n        - CSRF Token `does'nt` apply to this method\n\n```\n$form-\u003erules([\n    \"s:name\" =\u003e 'Please enter a name',\n])-\u003ebefore(function($response){\n\n    // execute code\n});\n```\n\n### After\n- Expects a `closure` function as the param\n    - Will always execute no matter the request method type\n        - CSRF Token `does'nt` apply to this method\n\n```\n$form-\u003eafter(function(){\n    // execute code\n});\n```\n\n### Has Error\n- Returns bool `true\\|false`\n\n```\n$form-\u003ehasError();\n```\n\n### Is Validated\n- Returns bool `true\\|false`, When Form has already been validated\n\n```\n$form-\u003eisValidated();\n```\n\n## Reset Error\n- Even if you're inside the `success() method`\n- With this helper, you can be able to reset the class, to error class\n\n```\n-\u003esave(function($response){\n\n    $availableUserAmount = 900;\n\n    \u003c!-- Lets say for instance, users have wallet balance and the form request has no error --\u003e\n    \u003c!-- But you need to perform another error validator before you allow request to pass through --\u003e\n    \u003c!-- Don't forget the add the \"return;\" key to stop any other code from executing --\u003e\n\n\n    if($response-\u003eamount \u003e $availableUserAmount){\n        $response-\u003ereset();\n        $response-\u003emessage = \"Your wallet balance is too low, Please recharge before you can Subscribe to Plan!\";        \n        return;\n    }\n\n    // perform other request before\n});\n```\n\n## Only\n- Takes a param as an `array` \n    - `keys` of data only needed, from the `form param`\n\n```\n-\u003esave(function($response){\n    //\n    $data = $response-\u003eonly(['password', 'username']);\n});\n```\n\n## Except\n- Exact opposite of `only()` method\n\n```\n-\u003esave(function($response){\n    \n    $data = $response-\u003eexcept(['_token']);\n});\n```\n\n## Has\n- Takes a param as `string` input name\n    - Returns boolean as `true|\\false`\n\n```\n-\u003esave(function($response){\n    \n    if($response-\u003ehas('remeber_me')){\n        // execute code\n    }\n});\n```\n\n## Old\n- Takes a param as `string` and return old inserted data\n    - Second parameter is [optional] `mixed data`. \n    - It's helper class can be called, using -- `old()`\n\n```php\n$form-\u003erules([\n    \"s:password\" =\u003e 'Please enter a name',\n    \"s:retype_pass:!==:{$form-\u003eold('password')}\" =\u003e 'Password mismatch, Please enter same password',\n]);\n```\n\n- or \n```html\n\u003cinput type=\"email\" name=\"email\" value=\"\u003c?= old('email', 'default_value')\u003e\"\u003e\n```\n![Sample Session Schema](https://raw.githubusercontent.com/tamedevelopers/validator/main/old.png)\n\n## GetForm\n- Return all submitted form data as an `array`\n\n```php\n-\u003esave(function($response){\n\n    $data = $response-\u003egetForm();\n});\n```\n\n## Merge\n- Same as PHP function `array_merge`\n    - Merge two array data together\n    - Second data will always repalace any matched key data in the first array\n\n```php\n-\u003esave(function($response){\n    \n    $data = [\n        'name' =\u003e 'Lorem Name',\n        'user_id' =\u003e rand(10000, 99999),\n    ];\n\n    $param = $response-\u003emerge($data, [\n        'password' =\u003e md5($param['password'])\n    ]);\n});\n```\n\n## Only Data\n- Return only `data passed` from set of given array elements.\n\n| Keys     |  Data                       |\n|----------|-----------------------------|\n| `array`  |  Main data to select from   |\n\n```php\n-\u003esave(function($response){\n\n    $data = $response-\u003eonlyData(['email', 'password'], [\n        'email'     =\u003e 'mailer@mail.com', \n        '_token'    =\u003e md5('token'), \n        'age'       =\u003e 17,\n        'password'  =\u003e 'test',\n    ]);\n\n// Only ['email', 'password'] will be returned.\n});\n```\n\n## Except Data\n- Exact opposite of `onlyData()` method\n\n| Keys            |  Data                       |\n|-----------------|-----------------------------|\n| Keys are array  |  Main data to select from   |\n\n```php\n-\u003esave(function($response){\n    \n    $data = $response-\u003eexceptData(['_token'], [\n        'email'     =\u003e 'mailer@mail.com', \n        '_token'    =\u003e md5('token'), \n        'password'  =\u003e 'test'\n    ]);\n\n// Return all array element, except ['_token']\n});\n```\n\n## Get Message and Class\n| key     |      Description           |\n|---------|----------------------------|\n| message | `Message` This convert all error messages and return as a string with `\u003cbr\u003e` |\n| class   | `Class name` Class name on error and success  |\n\n\n```php\n$form-\u003egetMessage();\n$form-\u003egetClass();\n```\n![Sample Session Schema](https://raw.githubusercontent.com/tamedevelopers/validator/main/getErrorMessage.png)\n\n\n## Collection\n- Forms `param` returns a Collection Class\n    - This enable us access property as an `object` or `array index`\n\n```php\n$form-\u003erules([\n    \"string:country:==:0\"   =\u003e 'Please Select a Country',\n    \"email:email\"           =\u003e 'Please enter a valid email address',\n])-\u003esave(function($response){\n\n    $param = $response-\u003eparam;\n\n\n    $param-\u003ecountry;\n    $param['country']\n\n// As you can see, we're able to access data in both ways without errors\n});\n```\n\n## Collection Methods\n\n|    Methods        |          Description                |\n|-------------------|-------------------------------------|\n|  toArray()        |  `array` Convert items to array     |\n|  toObject()       |  `object` Convert items to object   |\n|  toJson()         |  `string` Convert items to json     |\n\n\n## toObject\n- Takes a param as `mixed` data\n    - Converts to an `Object` data\n\n```php\n$form-\u003etoObject([\n    'food' =\u003e 'Basmati Rice'\n]);\n```\n\n## toArray\n- Takes a param as `mixed` data\n    - Converts to an `Array` data\n\n```php\n$form-\u003etoArray([\n    'food' =\u003e 'Basmati Rice'\n]);\n```\n\n## toJson\n- Takes a param as `mixed` data\n    - Converts to an `Json` data\n\n```php\n$form-\u003etoJson([\n    'food' =\u003e 'Basmati Rice'\n]);\n```\n\n## Helpers\n\n| function  | Description                       |\n|-----------|-----------------------------------|\n| old()     | Inherit instance of `(new Validator)` old() method    |\n| form()    | Return instance of `(new Validator)` class            |\n\n\n## Useful links\n\n- @author Fredrick Peterson (Tame Developers)\n- [Lightweight - PHP Form Validator](https://github.com/tamedevelopers/validator)\n- If you love this PHP Library, you can [Buy Tame Developers a coffee](https://www.buymeacoffee.com/tamedevelopers)\n- Link to Youtube Video Tutorial on usage will be available soon\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftamedevelopers%2Fvalidator","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftamedevelopers%2Fvalidator","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftamedevelopers%2Fvalidator/lists"}