Trongate PHP Framework Docs
Introduction
Basic Concepts
Understanding Routing
Intercepting Requests
Module Fundamentals
Database Operations
Templates
Helpers
Form Handling
Form Validation
Working With Files
Image Manipulation
Working With Dates & Times
Language Control
Authorization & Authentication
Tips And Best Practices

Retrieving Form Data

One function handles all POST data: .

Basic Usage

  • $field_name - field name, null, or true (to get all data)
  • $clean_up - trim and collapse whitespace (optional, default: false)
  • $cast_numeric - convert numbers to int/float (optional, default: false)

Get All Data (Returns array)

Get a Specific Field

Understanding the $clean_up Parameter

When $clean_up is true, performs two operations on string values:

  1. Trimming: Removes whitespace from the beginning and end of strings
  2. Collapsing: Reduces multiple consecutive spaces, tabs, or line breaks to a single space

Numeric Casting

When $cast_numeric is true, purely numeric strings are converted to their appropriate PHP types:

Nested Data Access & JSON Payloads

post() automatically detects and parses JSON, and supports both common array notations:

Dot Notation (JSON/Nested Arrays)

Bracket Notation (Form/Arrays)

JSON parsing: Malformed JSON throws an Exception. Wrap API endpoints in try-catch blocks.

Checkbox Values: A Special Case

Checkboxes require special handling because unchecked checkboxes don't submit any data. This is HTML behavior, not Trongate.

This pattern is essential for proper checkbox handling in Trongate applications.

Real-World Patterns

Form Processing Example

API Endpoint with JSON

The function is solely for data retrieval, cleanup, and type casting. It does not perform HTML escaping.

Always use the framework's output helper (i.e., ) or htmlspecialchars() when displaying retrieved form data in a view to prevent Cross-Site Scripting (XSS) vulnerabilities.

Important Notes

  • Missing fields return empty string ('').
  • Data is parsed once and cached for the duration of the request.
  • Use post() for all data, post('field', true) for specific fields (recommended).
  • Checkboxes require (bool) conversion for views and (int) (bool) for database.
  • Data validation must be handled separately using the Validation class.

Instantly view the entire request POST payload (including JSON and nested arrays) by combining with the helper. For example:

This makes form debugging super easy!