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
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:
- form_button() Generates a generic button that requires JavaScript to perform actions.
- form_checkbox() Outputs a checkbox input for binary choices.
- form_close() Closes the form and automatically injects a CSRF token.
- form_dropdown() Generates a select menu allowing single or multiple selections.
- form_email() Creates an email input with built-in browser validation.
- form_hidden() Adds hidden fields for data that should not be visible to users.
- form_input() Generates a standard text input field.
- form_number() Outputs a numeric input with browser-level validation and controls.
-
form_open()
Outputs the opening
<form>tag and initializes a new form. - form_open_upload() Opens a form configured for file uploads using multipart encoding.
- form_password() Produces a password field that masks user input.
- form_radio() Creates a radio button for mutually exclusive options.
- form_submit() Creates a submit button for sending form data to the server.
- form_textarea() Creates a multi-line text field for longer user input.
- post() Retrieves submitted POST, JSON, or multipart form data.
- validation_errors() Displays validation errors, supporting inline, grouped, or JSON output.
Building a Form
In a view file:
Output:
The form_close() 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.