PHPackages                             anandpilania/f3-validator - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Validation &amp; Sanitization](/categories/validation)
4. /
5. anandpilania/f3-validator

ActiveLibrary[Validation &amp; Sanitization](/categories/validation)

anandpilania/f3-validator
=========================

Validator package for FatFreeFramework.

v1.2.5(6y ago)52712MITPHP

Since Sep 16Pushed 4y ago2 watchersCompare

[ Source](https://github.com/AnandPilania/f3-validator)[ Packagist](https://packagist.org/packages/anandpilania/f3-validator)[ RSS](/packages/anandpilania-f3-validator/feed)WikiDiscussions master Synced today

READMEChangelog (2)Dependencies (1)Versions (11)Used By (0)

f3-validator
============

[](#f3-validator)

[![Hits](https://camo.githubusercontent.com/e05768137cda6792228aa658fad94524b0811f5d48898ebb27203f0164a18bb0/68747470733a2f2f686974732e736565796f756661726d2e636f6d2f6170692f636f756e742f696e63722f62616467652e7376673f75726c3d68747470732533412532462532466769746875622e636f6d253246416e616e6450696c616e696125324666332d76616c696461746f7226636f756e745f62673d253233464633383633267469746c655f62673d253233324333453530267469746c653d6869747326656467655f666c61743d66616c7365)](https://hits.seeyoufarm.com)

Easy to use Validation package for Fatfree-framework with using F3 built-in translations. You can also use it directly in the model.

**NOTE:** This package port some classes and ideas from [illuminate/validator](https://github.com/illuminate/validator).
**NOTE:** SAMPLE DICT/LANG FILE IS INCLUDED AS `en.php.sample`, use this for reference.

\## Usage

- 1: Initializing, passing data and validate:

    `$validator = new Validator(

    ```
      array('name' => 'Anand Pilania', 'email' => 'abc@def.ge'),

      array('name' => 'required|min:3|max:60', 'email' => 'required|unique:Models\User|email')

    ```

    )-&gt;validate();`

    **NOTE:** You can also pass more data to the `validate` method.

    - Another method:

        `$validator = Validator::instance()-&gt;validate(

        ```
          array('name' => 'Anand Pilania', 'email' => 'abc@def.ge'),

          array('name' => 'required|min:3|max:60', 'email' => 'required|unique:NAMESPACED_MODEL_CLASS_OR_CONFIG_MODEL.PARAM`|email')

        ```

        );`
- 2: Get validation status (return -&gt; true/false):

    `$validator->passed();`
- 3: If validation failed, retrieve the failed attribute with formatted messages/errors (return -&gt; array):

    `$validator->errors();`

Setup
-----

[](#setup)

- `composer require anandpilania/f3-validator`

Rules
-----

[](#rules)

### Used without paramater

[](#used-without-paramater)

- `boolean` OR `bool`, `string`, `integer` OR `int`, `array`, `numeric`, `alpha`, `alpha_num`, `alpha_dash`,
- `url`, `nullable`, `json`, `required`, `confirmed`, `active_url`, `email`, `ip`, `ipv4`, `ipv6`, `filled`

### Used with parameters

[](#used-with-parameters)

- `min`, `max`, `size`, `between` - `min:6`, `max:255`, `size:3`, `between:1,3`
- `unique` - `unique:NAMESPACED_MODEL_CLASS_OR_CONFIG_MODEL`
- ...

USING IN MODEL
--------------

[](#using-in-model)

- RECOMMENDED : Validate user input in controllers is the recommended way

### CONTROLLER

[](#controller)

```
`$validator = Validator::instance()->validate($f3->get('POST'), array(
	'field' => 'required|CHECK_PARAM' // EG: 'email' => 'required|email|unique:Models\User'
));`

`if(!$validator->passed()) {
	return/flash $validator->errors();
}`

```

USING IN MODEL
--------------

[](#using-in-model-1)

- You can also use this validator directly into your model: FOR EX: Validatin on `beforesave` trigger: (This example is used with [ikkez/f3-cortex](https://github.com/ikkez/f3-cortex))

### Model

[](#model)

```
`protected $validator;
 public function __construct() {
      parent::__construct();
      $saveHandler = function() {
	       foreach($this->getFieldConfiguration() as $field => $conf) {
        	    if(isset($conf['validate'])) {
            	    $rules[$field] = $conf['validate'];
            	    $data[$field] = $this->get($field);
            	    if(Validator::instance()->str_contains($conf['validate'], 'confirmed')) {
        	    	   $confirmation = $field.'_confirmation';
                	   $data[$field.'_confirmation'] = null !== $f3->get('POST.'.$confirmation)?$f3->get('POST.'.$confirmation):$f3->get('GET.'.$confirmation);
            	    }
        	    }
    	    }
    	    $this->validator = Validator::instance()->validate($data, $rules);
	        return $this->validator->passed();
	   };
   $this->beforesave($saveHandler);
}`

```

### Controller

[](#controller-1)

```
`$model = new MODEL;
 $model->copyFrom($f3->get('POST'), array_keys($model->fieldConf));
 $mode->save();

 if($model->validator->passed()) {
 	// NO ERRORS
 }else{
 	// VAIDATION FAILED
	$errors = $model->validator->errors();
 }`

```

\--

### USING UNIQUE VALIDATOR (2 WAYS)

[](#using-unique-validator-2-ways)

- Simply pass the NAMESPACED\_MODEL\_CLASS =&gt; `unique:Models\User`
- Define in config as =&gt;

    INI =&gt; `MODEL.USERS = Models\User`HIVE =&gt; $f3-&gt;set('MODEL.USERS', 'Models\\User');

    and use it as `unique:users`

###  Health Score

32

—

LowBetter than 74% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity18

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity69

Established project with proven stability

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~77 days

Recently: every ~86 days

Total

10

Last Release

2413d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/b1209e551536746ac78a8a4b7f5a2cc13f776629484c441edc5d3f1a50edbea0?d=identicon)[AnandPilania](/maintainers/AnandPilania)

---

Top Contributors

[![AnandPilania](https://avatars.githubusercontent.com/u/14306728?v=4)](https://github.com/AnandPilania "AnandPilania (15 commits)")

---

Tags

f3fat-free-frameworkfatfreevalidation-libraryvalidatorF3fatfreeanandpilaniafatfreeframeworkf3-validator

### Embed Badge

![Health badge](/badges/anandpilania-f3-validator/health.svg)

```
[![Health](https://phpackages.com/badges/anandpilania-f3-validator/health.svg)](https://phpackages.com/packages/anandpilania-f3-validator)
```

###  Alternatives

[xfra35/f3-cron

Job scheduling for the PHP Fat-Free Framework

72106.5k](/packages/xfra35-f3-cron)[xfra35/f3-access

Route access control for the PHP Fat-Free Framework

6668.2k1](/packages/xfra35-f3-access)[ikkez/f3-validation-engine

Validation engine for Cortex and the PHP Fat-Free Framework

1220.6k1](/packages/ikkez-f3-validation-engine)[ikkez/f3-schema-builder

SQL Schema Builder Plugin for PHP Fat-Free Framework

5853.3k3](/packages/ikkez-f3-schema-builder)[xfra35/f3-multilang

Route localization plugin for the PHP Fat-Free Framework

4862.2k1](/packages/xfra35-f3-multilang)[ikkez/f3-cortex

A multi-engine ORM / ODM for the PHP Fat-Free Framework

11839.4k6](/packages/ikkez-f3-cortex)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
