The Trongate PHP Framework
Documentation
Introduction
Quick Start
Basic Concepts
Understanding Routing
Controllers
Views
Assets
Modules Calling Modules
Parent & Child Modules
Database Operations
Modules within Modules
Templates & Themes
Helpers Explained
Form Handling
Working with Files
The Module Import Wizard
Authorization & Authentication
The API Explorer
Best Practices

Help Improve Our Docs

If you’ve found an error, spotted something missing, or feel a section could be clearer or better explained, we’d love to hear from you. Your feedback helps keep the documentation accurate and useful for everyone.

Please report issues or suggest improvements on GitHub. Community input is invaluable in making the docs stronger.

Not comfortable with GitHub? No problem — you can also get in touch with us directly via our contact form. We welcome all feedback.

Retrieving Form Data

In Trongate, retrieving data submitted through HTML forms is both straightforward and secure. The framework provides a range of tools to help you access, clean, and process form data effectively. Whether you're working with standard form submissions or JSON payloads, Trongate ensures consistency and simplicity in handling user inputs.

Form Data Handling in Trongate

Trongate supports retrieving data across all HTTP methods (GET, POST, PUT, PATCH, DELETE). Form data can be retrieved seamlessly, whether it is submitted via form-encoded content or as JSON payloads. Additionally, the framework includes features to clean and normalise user input where required.

The post() Function

The post() function is a powerful tool for accessing form data. It allows you to retrieve data from any HTTP request and works with both form-encoded and JSON payloads. The function also includes an optional cleanup mechanism for trimming whitespace and normalising internal spaces.

Basic Usage

To retrieve the value of a specific form field, call the post() function with the field name:

This will return the value of the task_title field. If the field does not exist, the function will return an empty string.

Cleaning Up Data

By passing true as the second argument to post(), you can clean up the retrieved data. This process trims any leading or trailing spaces and reduces multiple spaces within the string to a single space:

Clarification: The second argument (true) ensures that the retrieved value is cleaned up. This means:

  • Leading and trailing spaces are removed.
  • Multiple internal spaces are replaced with a single space.

Therefore, if a user submits a value of:

   Michael           Jackson   

The cleaned result will be:

Michael Jackson

Working with Form Data in Controllers

Below is an example of how you might retrieve and process form data in a Trongate controller:

Conclusion

Retrieving form data in Trongate is designed to be straightforward, secure, and efficient. By using tools like the post() function, you can handle user input with confidence, whether it originates from standard HTML forms or complex JSON payloads. This consistent approach ensures a smooth development experience for handling form submissions across different scenarios.

×