webCOMAND

request::post()

The post method provides access to HTTP (and HTTPS) POST query parameters.  POST parameters are made available to a web page through a form submission or AJAX POST or other HTTP POST request.

Prototype

string post(string $key = NULL, array $options = [])

Parameters

  • key - Name of the parameter to retrieve.  If NULL or no key is provided, an associative array of all parameters will be returned.
  • options - Array of options with the following key/value pairs.
    • default - A value to use if the request does not include the query parameter.

Return

If the POST parameter exists, the value is returned as a string, including an empty string.  Otherwise, FALSE is returned.

Example

The following HTML form will POST a "search" parameter with the value "test".

<html>
<body>
    <h1>Search</h1>
    <form method="POST">
        <input name="search" type="text" value="test" />
        <input type="submit" />
    </form>
</body>
</html>

The following PHP code will retrieve the posted search value.

// retrieve the value of the "search" POST parameter
$request = new \io_comand_web\request();
$search = $request->post('search', ['default' => '']);