Skip to content
Greg Bowler edited this page Jun 24, 2018 · 14 revisions

The Input repository is separately maintained at https://github.com/PhpGt/Input

By default, PHP exposes all user input in the superglobal variables $_GET, $_POST and $_FILES, which are readable and writable by any code, including third party libraries.

All superglobals are protected within WebEngine, and instead user input is encapsulated within the Input object, which is available as the input property of your application's Logic classes.

Reading an input value from within a Logic class

The get function of the Input class will return the data matching the provided key, or null if the user input doesn't exist.

public function getUserInput() {
// Read the "telephone" parameter from the query string or post body:
	$telephone = $this->input->get("telephone");

// Read the "name" parameter, supplying a default if input is empty:
	$name = $this->input->get("name") ?? "Anon";
}

It doesn't matter what HTTP verb (GET, POST, PUT, DELETE, etc.) is used for the request as input is accessed in the same way for all verbs.

You can however specify only to load the input value from the querystring, body or files section of the request parameters. This can be done by passing in one of the following constants as the second parameter to the get function: Input::DATA_QUERYSTRING, Input::DATA_BODY, Input::DATA_FILES. The default is Input::DATA_COMBINED.

Returning a specific type of data

// getFile

// getDateTime

Checking the presence of specific user input

// has

// hasValue

// hasQueryStringParameter

// hasBodyParameter

// hasFile

Passing input data to functions

The code in your application's Logic classes has full access to the user input, but you don't want to pass all user input around to all other areas of code. Instead, it is possible to call functions with only the user input they are required to know about. For example, in an e-commerce application, only the payment processor needs to be handed the user's credit card details, and not any other areas of code.

The with and without functions

// with returns a Trigger

Triggering a callback when there's matching user input

// when only calls callback when provided input is present

Using do triggers

// Shorthand for when - easily hook up button presses to callbacks

Handling multiple input

// Square brackets - MultipleInputDatum

// getMultipleFile

// getMultipleDateTime

Handling file uploads

// getFile, getMultipleFile

// move

// getFileInfo, getRealPath, getOriginalName, getOriginalExtension, getSize, getMimeType

// FailedFileUpload

Clone this wiki locally