Slide 1

Slide 1 text

nether input

Slide 2

Slide 2 text

what it does  handle input from GET, POST, or any other named dataset from a chainable OOP interface.  define different functions, validators, or sanitisers to different fields.  define a default function to handle any field without a specific handler.  reuse the same filter sets on different datasets.  case insensitive (by default) – your OOP code standards do not have to match the HTML naming conventions.  lightweight in both dependency and api.

Slide 3

Slide 3 text

form setup a generic html form. nothing special here.

Slide 4

Slide 4 text

filter setup $input = (new Nether\Input\Filter($_POST)) ->Username(function($v){ if(strlen($v) < 3) return false; if(preg_match('/[^a-z0-9]/i',$v)) return false; return $v; }) ->Email(function($v){ return filter_var($v,FILTER_VALIDATE_EMAIL); }) ->Password(function($v){ if(strlen($v) < 8) return false; return $v; }); assign functions to specific form values by calling them as methods on the filter object, supplying them with a callback to execute. $input->FieldName($callback); this can be defined ahead of time as part of your application setup if you feel like you are going to use it enough, or you can just define it before you plan to use it.

Slide 5

Slide 5 text

filter setup (cont.) $input = (new Nether\Input\Filter($_POST)) ->Username(function($v){ ... }) ->Email(function($v){ ... }) ->Password(function($v){ ... }); regardless of where you set it up, all your validation logic is now grouped together and out of the way. code folding for the win.

Slide 6

Slide 6 text

application logic if(!$input->Username) echo User::ErrorInvalidUsername; elseif(!$input->Email) echo User::ErrorInvalidEmail; elseif(!$input->Password) echo User::ErrorInvalidPassword; else { $user = User::Create([ 'Username' => $input->Username, 'Email' => $input->Email, 'Password' => $input->Password ]); $router->Redirect('/dashboard/'); } access the data with your filters automatically applied just by reading out a property that matches the field name. echo $input->FieldName; now your signup.php actual controller logic can be fairly clean.

Slide 7

Slide 7 text

filter reuse $result = $db->Query($sql,$args); while($row = $result->Next()) { $filter->SetDataset($row); // ... do stuff with the data. } after you define a bunch of filters, you can change out the dataset to reuse the filters multiple times.

Slide 8

Slide 8 text

useful for output too SetDefaultFunction(function($v){ return htmlentities($v); }); ?> Password ?>" /> here is that same html form from earlier, now with support for prefilling on failure. a great first line of defense against cross-site scripting problems like script tag injection.

Slide 9

Slide 9 text

how to install “require”: { “netherphp/input”: ”~1.0.0” } install via composer. input depends on two other nether libraries: object and option. they are small though and automatically installed by composer - you do not need the full nether stack to use input.

Slide 10

Slide 10 text

about  site: http://nether.io  repository: http://github.com/netherphp/input  developer: bob majdak jr @bobmajdakjr all components of the nether framework are released under the bsd 3-clause licence.