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 date input with browser-native date picker.
- Generates a local datetime input with browser-native controls.
- Generates a select menu allowing single or multiple selections.
- Creates an email input with built-in browser validation.
- Generates a file picker input for uploading files.
- Adds hidden fields for data that should not be visible to users.
- Generates a standard text input field.
- Generates an HTML label element for form fields.
- Generates a month input with browser-native month picker.
- 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.
- Generates a search input with optional clear button.
- Creates a submit button for sending form data to the server.
- Creates a multi-line text field for longer user input.
- Generates a time input with browser-native time picker.
- Generates a week input with browser-native week picker.
- 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.
We're continually improving the Trongate documentation. If anything is incorrect, unclear, incomplete, or could be better, we'd genuinely appreciate your input.
Share your thoughts in the Documentation Feedback.