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.
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.
->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.
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.
return htmlentities($v); }); ?> <form method="post"> <input type="text" name="username" name="<?php echo $post->Username ?>" /> <input type="text" name="email" name="<?php echo $post->Email ?>" /> <input type="password" name="password“ name="<?php echo $post->Password ?>" /> <input type="submit" value="Sign Up" /> </form> 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.
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.