Access GET, POST or COOKIE input variables and more ($input API variable as a function)

  • Default behavior with no arguments is to return the $input API variable.
  • If given just a $type argument (like “get” or “post”), it will return a WireInputData object for that type.
  • If given a $type and $key arguments, it will return the value, or null if not present.
  • If $sanitizer argument given, the returned value will also be run through the given sanitizer.
  • If the $sanitizer argument is an array, the returned input value must be within the given list, or null if not (3.0.125+).
  • If $fallback argument given, it will return the fallback value if input value was not present or not valid (3.0.125+).
  • See the WireInput::get() method for all options.

Example

// Can be used the same way as the $input API variable
// In examples below the “post” can also be “get” or “cookie”
$input = input(); // Returns $input API var (WireInput)
$post = input()->post(); // Returns $input->post (WireInputData instance)
$foo = input()->post('foo'); // Returns POST variable “foo”
$bar = input()->post('bar', 'text'); // Returns “bar” after text sanitizer (3.0.125+)
$s = input()->post('s', ['foo', 'bar', 'baz']); // POST var “s” must match given list (3.0.125+)

// You can also move the arguments all to the function call if you prefer:
$s = input('get', 'sort'); // Returns GET var “sort”
$s = input('get', 'sort', 'fieldName'); // Returns “sort” after “fieldName” sanitizer
$s = input('get', 'sort', ['title', 'created']); // Require sort to be one in given array (3.0.125+)
$s = input('get', 'sort', ['title', 'created'], 'title'); // Same as above, fallback to 'title' (3.0.125+)

Usage

// basic usage
$wireInput = input();

// usage with all arguments
$wireInput = input(string $type = '', string $key = '', string $sanitizer = null, $fallback = null);

Arguments

NameType(s)Description
type (optional)string

Optionally indicate "get", "post", "cookie" or "whitelist"

key (optional)string

If getting a value, specify name of input property containing value

sanitizer (optional)string

Optionally specify sanitizer name to run value through, or in 3.0.125+ may also be an array of allowed values.

fallback (optional)string, int, null

Value to fallback to if input not present or invalid

Return value

WireInput WireInputData array string int null


Functions methods and properties

API reference based on ProcessWire core version 3.0.133

Twitter updates

  • ProcessWire 3.0.133 adds a useful new Page::meta() method for a new type of page-specific persistent data storage, adds the ability for users to create their own bookmarks in Lister, and has a handy and time saving update for the asmSelect input type— More
    14 June 2019
  • New post: This week we’ll take a look at 3 different WEBP image strategies that you can use in ProcessWire 3.0.132+. Then we’ll dive into a major update for the Google Client API module, and finish up by outlining some useful new updates in FormBuilder— More
    31 May 2019
  • New post: This week we've added WEBP support in ProcessWire thanks to a GitHub pull request from Horst Nogajski. This enables you to have highly optimized image output in PW and I think you’ll really like the difference it makes— More
    24 May 2019

Latest news

  • ProcessWire Weekly #266
    In the 266th issue of ProcessWire Weekly we're going to take a closer look at ProcessWire 3.0.133 (dev), introduce a third party module called Repeater Images, and highlight a recently released site belonging to the Australian Antarctic Division. Read on!
    Weekly.pw / 15 June 2019
  • ProcessWire 3.0.133 core updates
    ProcessWire 3.0.133 adds a useful new $page->meta() method for a new type of page-specific persistent data storage, adds the ability for users to create their own bookmarks in Lister, and has a handy and time saving update for the asmSelect input type. Read on for all the details, examples and screenshots.
    Blog / 14 June 2019
  • Subscribe to weekly ProcessWire news

“I am currently managing a ProcessWire site with 2 million+ pages. It’s admirably fast, and much, much faster than any other CMS we tested.” —Nickie, Web developer