File src/addon/POSTValidator.php

class Lia\Addon\POSTValidator

When activated, it unsets $_POST and then only re-sets it after validation
See source code at /src/addon/POSTValidator.php

Constants

Properties

  • public string $fqn = 'lia:server.postvalidator';
  • public readonly \Lia\Utility\InputValidator $validator;
  • protected array $post; $_POST is copied to here

Methods

  • static public function activate(\Lia $lia) Enable for the given instance of liaison. Sets $_POST = []. Re-populates $_POST when validations are successful.
  • static public function activateForPackage(\Lia\Package $package) Hooks into \Lia\Hooks::ROUTES_FILTERED, to activate only if the given package is requested by the route.
  • static public function from(\Lia $lia): selfstatic
  • public function __construct(\Lia\Package $package=null)
  • public function dump() Print all $_POST values and exit
  • public function validate(string $key, arraystringnull $rules = null, callable $validation_function null): bool Check if the given entry matches expectations. You may pass BOTH $rules AND $validation_function, or you may pass just one (your choice). If you pass both, then both $rules AND $validation_function MUST return TRUE for validation to pass. If you pass only $key, then it is considered valid as long as $key is set in $_POST. When validation passes, $_POST[$key] is populated with the validated value.