Repository navigation
Post
Pair\Helpers\Post is a legacy static helper for request values. It does not expose submitted fields as object properties.
Use it when maintaining existing form and ActiveRecord flows that already depend on its casting rules. For new explicit web controllers, prefer Input; for JSON API modules, use Request.
-
get()reads$_POSTwhenREQUEST_METHODis exactlyPOST; otherwise it reads$_REQUEST. - A trailing
[]is removed from field names, and spaces become underscores. - Typed helpers cast values; they do not validate input shape, authorization, or domain rules.
- Casting obtains the
Applicationsingleton, so use these helpers within an initialized Pair runtime.
| Method | Behavior |
|---|---|
get(string $name, string $type = 'string', mixed $default = null): mixed |
Reads a value and applies the selected cast. |
string(string $name, ?string $default = null): string |
Casts the value to a string. |
trim(string $name, ?string $default = null): string |
Reads a string and trims whitespace. |
int($name, $default = null): int |
Casts to an integer. |
float(string $name, ?float $default = null): float |
Casts to a float. |
bool(string $name, ?bool $default = null): bool |
Recognizes the strings true and false, otherwise uses a PHP boolean cast. |
array(string $name, ?array $default = null): array |
Casts to an array. |
date(string $name, ?DateTime $default = null): ?DateTime |
Parses a date using the current datepicker format and user timezone. |
datetime(string $name, ?DateTime $default = null): ?DateTime |
Parses a date-time using the current datepicker format and user timezone. |
Defaults are used for missing keys and are cast as well. An explicitly submitted empty string is not replaced by the default. With no explicit default, missing strings become '', integers become 0, booleans become false, and arrays become [].
use Pair\Helpers\Post;
$email = Post::trim('email');
$name = Post::trim('name');
$quantity = Post::int('quantity', 1);use Pair\Helpers\Post;
if (($_SERVER['REQUEST_METHOD'] ?? '') !== 'POST') {
throw new RuntimeException('POST required');
}
$payload = [
'email' => Post::trim('email'),
'name' => Post::trim('name'),
];
if (!filter_var($payload['email'], FILTER_VALIDATE_EMAIL)) {
throw new RuntimeException('Invalid email');
}This validates the email shape only. Cookie-authenticated writes still need CSRF validation and application authorization before persistence; see Form.
-
sent(string $name): boolchecks key presence in$_REQUEST, including a key whose value isnull. It does not use the same source-selection logic asget(). -
submitted(): boolreturns whether$_POSTis non-empty. It is not an HTTP method check: an empty POST or a JSON request can returnfalse.
- Do not assume POST keys always exist.
- Always normalize/cast values before persistence.
-
new Post()followed by$post->emaildoes not read request data; callPost::trim('email')or another static accessor. - Casting is permissive: for example
Post::bool()treats a non-empty unrecognized string such asoffastrue. UseInput::bool()when its explicit true/false vocabulary fits the endpoint. -
$_REQUESTis populated by PHP; changing$_POSTlater does not automatically synchronize it. Tests and custom adapters must set the intended source explicitly.
See also: Input, Request, Form, ActiveRecord, Controller.
Home · Setup · Configuration
Build with Pair 4
- Generator
- Controllers and responses
- Read models
- ActiveRecord and queries
- Forms and validation
- PairUI.js and HTML fragments
APIs and authentication
- API guide and CRUD
- Middleware and rate limits
- Users, sessions, and ACL
- Passkeys and social login
- Native mobile setup
Integrate and operate
- Integrations
- Runtime extensions and adapter keys
- Cache and cache stores
- Logs and observability
- PWA and push
- Packages and distribution
- Upgrade to v4