PHPackages                             netherphp/input - 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. [Search &amp; Filtering](/categories/search)
4. /
5. netherphp/input

ActiveLibrary[Search &amp; Filtering](/categories/search)

netherphp/input
===============

Input Handling.

v4.1.1(3y ago)0335[1 PRs](https://github.com/netherphp/input/pulls)1BSD-2-ClausePHPPHP &gt;=8.0CI failing

Since May 13Pushed 3mo agoCompare

[ Source](https://github.com/netherphp/input)[ Packagist](https://packagist.org/packages/netherphp/input)[ RSS](/packages/netherphp-input/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (3)Dependencies (3)Versions (17)Used By (1)

Nether Input
============

[](#nether-input)

[![nether.io](https://camo.githubusercontent.com/1d25e8f77a5ecda7c4a58a81ccdce025e46a8a293003582c77f95eb99cc7d5df/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6e65746865722d696e7075742d4336363144322e737667)](http://nether.io/) [![Code Climate](https://camo.githubusercontent.com/54b9b764024684034a27e78f08790c6cbbbc31152f3e3af507384a35f8a30846/68747470733a2f2f636f6465636c696d6174652e636f6d2f6769746875622f6e65746865727068702f696e7075742f6261646765732f6770612e737667)](https://codeclimate.com/github/netherphp/input) [![Build Status](https://camo.githubusercontent.com/c4eb830ed085cd2f5776795d75f5c9c13a3097e545ef21ddc048321dd674483d/68747470733a2f2f7472617669732d63692e6f72672f6e65746865727068702f696e7075742e737667)](https://travis-ci.org/netherphp/input) [![Packagist](https://camo.githubusercontent.com/d61eaaa52f91417d0fcf523244c744105fef80663ccbd47f936c84620f640adb/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f6e65746865727068702f696e7075742e737667)](https://packagist.org/packages/netherphp/input) [![Packagist](https://camo.githubusercontent.com/f0c2efdfac98ce14d682b124f2b4b05a79d093d54433fcee4b9f096b7b013d2c/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f6e65746865727068702f696e7075742e737667)](https://packagist.org/packages/netherphp/input)

An input filtering interface. It allows you to define a set of dynamic filters for input to be run applied just-in-time on your specified data source.

Super simple example:
---------------------

[](#super-simple-example)

```
$input = (new Nether\Input\Filter)
->Email(function($t){ return filter_var($t,FILTER_VALIDATE_EMAIL); });

// ... some time later...

$input->SetDataset($_POST);
if(!$input->Email) {
	throw new Exception('valid email address is required.');
}

```

To pull this off, things like your HTML form field names will need to follow the same rules as properties in PHP (alphanumeric and \_ starting with a letter). By default it is case insensitive, so you can send all lowercase from your URL if you want and then reference them in whateverCase YouChoose to use. That can be disabled if you are on a performance powertrip.

You can pass any array or object to the constructor or use SetDataset(). Typical uses would be for \_GET and \_POST but you could apply it to any named dataset that needs looked at. You can also change datasets at will, keeping any predefined filters intact.

Another Simple Example:
-----------------------

[](#another-simple-example)

Lets say we want to dump our POST data back into our form because there was some sort of validation error. This is the time where it is very easy to accidentally open yourself up to cross-site scripting problems. Input Filter can take care of that for you though by defining a default filter that all fields which do not have their own special filters for, get run through.

```
$data = (new Nether\Input\Filter($_POST))
->SetDefaultFunction(function($v){ return htmlspecialchars($v) });

// ... some time later...
