{"id":20179246,"url":"https://github.com/anandpilania/f3-validator","last_synced_at":"2025-04-10T04:45:39.893Z","repository":{"id":56947515,"uuid":"103775404","full_name":"AnandPilania/f3-validator","owner":"AnandPilania","description":"Validation package for FatFreeFramework.","archived":false,"fork":false,"pushed_at":"2021-05-16T09:09:31.000Z","size":21,"stargazers_count":5,"open_issues_count":0,"forks_count":2,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-03-24T06:03:15.352Z","etag":null,"topics":["f3","fat-free-framework","fatfree","validation-library","validator"],"latest_commit_sha":null,"homepage":null,"language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/AnandPilania.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2017-09-16T18:38:38.000Z","updated_at":"2022-11-13T10:55:27.000Z","dependencies_parsed_at":"2022-08-21T07:50:07.190Z","dependency_job_id":null,"html_url":"https://github.com/AnandPilania/f3-validator","commit_stats":null,"previous_names":[],"tags_count":10,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/AnandPilania%2Ff3-validator","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/AnandPilania%2Ff3-validator/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/AnandPilania%2Ff3-validator/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/AnandPilania%2Ff3-validator/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/AnandPilania","download_url":"https://codeload.github.com/AnandPilania/f3-validator/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248161237,"owners_count":21057552,"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","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":["f3","fat-free-framework","fatfree","validation-library","validator"],"created_at":"2024-11-14T02:25:42.919Z","updated_at":"2025-04-10T04:45:39.871Z","avatar_url":"https://github.com/AnandPilania.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# f3-validator\n\n[![Hits](https://hits.seeyoufarm.com/api/count/incr/badge.svg?url=https%3A%2F%2Fgithub.com%2FAnandPilania%2Ff3-validator\u0026count_bg=%23FF3863\u0026title_bg=%232C3E50\u0026title=hits\u0026edge_flat=false)](https://hits.seeyoufarm.com)\n\nEasy to use Validation package for Fatfree-framework with using F3 built-in translations. You can also use it directly in the model.\n\n**NOTE:** This package port some classes and ideas from [illuminate/validator](https://github.com/illuminate/validator).  \n**NOTE:** SAMPLE DICT/LANG FILE IS INCLUDED AS `en.php.sample`, use this for reference.\n\n## Usage\n\n- 1: Initializing, passing data and validate:\n\n\t`$validator = new Validator(\n\t\n\t\tarray('name' =\u003e 'Anand Pilania', 'email' =\u003e 'abc@def.ge'),\n\t\t\n\t\tarray('name' =\u003e 'required|min:3|max:60', 'email' =\u003e 'required|unique:Models\\User|email')\n\t\t\n\t)-\u003evalidate();`  \n\t\n\t\n\t**NOTE:** You can also pass more data to the `validate` method.\n\t\n\t\n\t* Another method:\n\t\t\n\t\t`$validator = Validator::instance()-\u003evalidate(\n\t\t\n\t\t\tarray('name' =\u003e 'Anand Pilania', 'email' =\u003e 'abc@def.ge'),\n\t\t\t\n\t\t\tarray('name' =\u003e 'required|min:3|max:60', 'email' =\u003e 'required|unique:NAMESPACED_MODEL_CLASS_OR_CONFIG_MODEL.PARAM`|email')\n\t\t\t\n\t\t);`\n\t\t\n\t\n- 2: Get validation status (return -\u003e true/false):\n\n\t`$validator-\u003epassed();`\n\t\n- 3: If validation failed, retrieve the failed attribute with formatted messages/errors (return -\u003e array):\n\n\t`$validator-\u003eerrors();`\n\t\t\n\n## Setup\n\n- `composer require anandpilania/f3-validator`\n  \n## Rules\n\n### Used without paramater\n * `boolean` OR `bool`, `string`, `integer` OR `int`, `array`, `numeric`, `alpha`, `alpha_num`, `alpha_dash`,\n * `url`, `nullable`, `json`, `required`, `confirmed`, `active_url`, `email`, `ip`, `ipv4`, `ipv6`, `filled`\n \n### Used with parameters\n *  `min`, `max`, `size`, `between` - `min:6`, `max:255`, `size:3`, `between:1,3`\n *  `unique` - `unique:NAMESPACED_MODEL_CLASS_OR_CONFIG_MODEL`\n *  ...\n\n## USING IN MODEL\n- RECOMMENDED : Validate user input in controllers is the recommended way\n\n### CONTROLLER\n\t`$validator = Validator::instance()-\u003evalidate($f3-\u003eget('POST'), array(\n\t\t'field' =\u003e 'required|CHECK_PARAM' // EG: 'email' =\u003e 'required|email|unique:Models\\User'\n\t));`\n\t\n\t`if(!$validator-\u003epassed()) {\n\t\treturn/flash $validator-\u003eerrors();\n\t}`\n\t\n\t\n## USING IN MODEL\n- You can also use this validator directly into your model:\nFOR EX: Validatin on `beforesave` trigger: (This example is used with [ikkez/f3-cortex](https://github.com/ikkez/f3-cortex))\n\n### Model\n\t`protected $validator;\n\t public function __construct() {\n\t      parent::__construct();\n\t      $saveHandler = function() {\n\t\t       foreach($this-\u003egetFieldConfiguration() as $field =\u003e $conf) {\n            \t    if(isset($conf['validate'])) {\n                \t    $rules[$field] = $conf['validate'];\n                \t    $data[$field] = $this-\u003eget($field);\n                \t    if(Validator::instance()-\u003estr_contains($conf['validate'], 'confirmed')) {\n            \t    \t   $confirmation = $field.'_confirmation';\n                    \t   $data[$field.'_confirmation'] = null !== $f3-\u003eget('POST.'.$confirmation)?$f3-\u003eget('POST.'.$confirmation):$f3-\u003eget('GET.'.$confirmation);\n                \t    }\n            \t    }\n        \t    }\n        \t    $this-\u003evalidator = Validator::instance()-\u003evalidate($data, $rules);\n\t\t        return $this-\u003evalidator-\u003epassed();\n    \t   };\n\t   $this-\u003ebeforesave($saveHandler);\n\t}`\n\n### Controller\n\t`$model = new MODEL;\n\t $model-\u003ecopyFrom($f3-\u003eget('POST'), array_keys($model-\u003efieldConf));\n\t $mode-\u003esave();\n\t \n\t if($model-\u003evalidator-\u003epassed()) {\n\t \t// NO ERRORS\n\t }else{\n\t \t// VAIDATION FAILED\n\t\t$errors = $model-\u003evalidator-\u003eerrors();\n\t }`\n--\nhttp://about.me/anandpilania\n\n### USING UNIQUE VALIDATOR (2 WAYS)\n * Simply pass the NAMESPACED_MODEL_CLASS =\u003e `unique:Models\\User`\n * Define in config as =\u003e \n\t\n\tINI =\u003e `MODEL.USERS = Models\\User` \n\tHIVE =\u003e $f3-\u003eset('MODEL.USERS', 'Models\\User');\n\t\n\tand use it as `unique:users`\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fanandpilania%2Ff3-validator","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fanandpilania%2Ff3-validator","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fanandpilania%2Ff3-validator/lists"}