Form Helpers

The Form Helpers are lightweight functions that simplify the creation of HTML forms and form elements. They provide convenient methods for generating input fields, textareas, dropdowns, buttons, and complete form tags with built-in CSRF protection. These helpers also include functions for retrieving POST data with support for JSON payloads and displaying validation errors in multiple formats.

form_button()

Generates an HTML button element with type="button". These buttons require JavaScript for interactivity and do not submit forms.

form_checkbox()

Generates an HTML checkbox input element. Checkboxes allow users to select or deselect a single option.

form_close()

Closes an HTML form. Always use this function instead of manually writing </form>. It automatically adds a CSRF token for security and handles validation error highlighting.

form_date()

Generates an HTML date input field with a native browser date picker. The input always submits dates in ISO 8601 format (YYYY-MM-DD), regardless of how the browser displays the date to the user.

form_datetime_local()

Generates an HTML datetime-local input field with a native browser date and time picker. The input combines date and time selection in a single control and always submits in ISO 8601 format (YYYY-MM-DDTHH:MM).

form_dropdown()

Generates an HTML select menu (dropdown). Creates a list of options where users can select one or multiple values.

form_email()

Generates an HTML email input field with type="email". Provides built-in browser email validation.

form_file_select()

Generates an HTML file input element. Requires forms to use form_open_upload() for proper file upload handling.

form_hidden()

Generates a hidden input field for storing data that should not be visible to users but is submitted with the form.

form_input()

Generates a standard text input field with type="text". This is the most commonly used form input type.

form_label()

Generates an HTML <label> element. Labels improve accessibility and usability by associating descriptive text with form input fields.

form_month()

Generates an HTML month input field with a native browser month picker. The input allows users to select a month and year, submitting data in YYYY-MM format.

form_number()

Generates an HTML number input field with type="number". Provides built-in browser number validation and step controls.

form_open()

Generates the opening tag for an HTML form. This is typically the first function called when building a form in Trongate.

form_open_upload()

Generates the opening tag for an HTML form configured for file uploads. This function is identical to form_open() but automatically adds the enctype="multipart/form-data" attribute required for file submissions.

form_password()

Generates an HTML password input field with type="password". This input type obscures entered text with dots or asterisks for secure password entry.

form_radio()

Generates an HTML radio button input element. Radio buttons allow users to select exactly one option from a group of choices.

form_search()

Generates an HTML search input field with type="search". Modern browsers provide enhanced search features including a clear button, specialized mobile keyboards, and sometimes integrated history.

form_submit()

Generates an HTML submit button element with type="submit" for sending form data to the server.

form_textarea()

Generates an HTML textarea element for multi-line text input. Textareas are ideal for longer content like comments, descriptions, or messages.

form_time()

Generates an HTML time input field with a native browser time picker. The input always submits time in 24-hour format (HH:MM or HH:MM:SS), regardless of how the browser displays the time to the user.

form_week()

Generates an HTML week input field with a native browser week picker. The input allows users to select a week and year, submitting data in YYYY-W## format (ISO 8601 week numbering).

post()

Retrieves submitted form data from POST requests, JSON payloads, or multipart form data. This unified function handles all incoming request data with support for nested structures and automatic parsing.

validation_errors()

Displays validation error messages stored in the session. This flexible function supports three output modes: general error display, inline field-specific errors, and JSON error responses for APIs.