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

Form Helpers

Trongate's form helpers let you easily build HTML forms without the tedium. Call a function. Get perfect HTML.

Zero config. Just functions:

  • Generates a generic button that requires JavaScript to perform actions.
  • Outputs a checkbox input for binary choices.
  • Closes the form and automatically injects a CSRF token.
  • Generates a select menu allowing single or multiple selections.
  • Creates an email input with built-in browser validation.
  • Adds hidden fields for data that should not be visible to users.
  • Generates a standard text input field.
  • Outputs a numeric input with browser-level validation and controls.
  • Outputs the opening <form> tag and initializes a new form.
  • Opens a form configured for file uploads using multipart encoding.
  • Produces a password field that masks user input.
  • Creates a radio button for mutually exclusive options.
  • Creates a submit button for sending form data to the server.
  • Creates a multi-line text field for longer user input.
  • Retrieves submitted POST, JSON, or multipart form data.
  • Displays validation errors, supporting inline, grouped, or JSON output.

Building a Form

In a view file:

Output:

The function automatically handles the insertion of a hidden CSRF token field, so developers do not need to manually include it in their forms.


File Uploads

For forms that accept files, just use form_open_upload() instead of form_open(). It adds the required enctype="multipart/form-data" automatically. No extra arguments needed.

In a view file:

Output:


Adding Attributes

All form helpers accept an optional third parameter: an associative array of HTML attributes.

In a view file:

Output:

Form handling (in any web development framework!) has lots of moving parts.

Check out the Form Handling chapter for a complete walkthrough of how to perform form handling with Trongate.

Looking for a super fancy way to do form handling but without page refreshes?

Trongate MX has you covered!

Check out the Trongate MX documentation for more information.