Trongate PHP Framework Docs
Introduction
Quick Start
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
Security
Tips And Best Practices

Form Helper Reference

Quick reference for all form helper functions in Trongate.

Form Tags

Function Parameters Returns
$location, $attributes Opening <form> tag
$location, $attributes Opening <form enctype="multipart/form-data">
None CSRF token + </form> tag

Examples

View File
echo form_open('users/submit');
echo form_open('users/submit', ['id' => 'user-form']);
echo form_open_upload('products/upload');
echo form_close();

Text Input Fields

Function Type Parameters
text $name, $value, $attributes
email $name, $value, $attributes
password $name, $value, $attributes
number $name, $value, $attributes
search $name, $value, $attributes
url $name, $value, $attributes
hidden $name, $value, $attributes
file $name, $attributes

Examples

View File
echo form_input('username', $username);
echo form_email('email', $email, ['placeholder' => '[email protected]']);
echo form_password('password');
echo form_number('quantity', $quantity, ['min' => '1', 'max' => '100']);
echo form_search('q', $q, ['placeholder' => 'Search...']);
echo form_url('website', $website, ['placeholder' => 'https://example.com']);
echo form_hidden('user_id', $user_id);
echo form_file_select('document', ['accept' => '.pdf']);

Date and Time Input Fields

Function Type Format Parameters
date YYYY-MM-DD $name, $value, $attributes
time HH:MM $name, $value, $attributes
datetime-local YYYY-MM-DDTHH:MM $name, $value, $attributes
month YYYY-MM $name, $value, $attributes
week YYYY-W## $name, $value, $attributes

For additional guidance, check out the chapter on Working With Dates & Times

Examples

View File
echo form_date('due_date', $due_date);
echo form_date('birth_date', $birth_date, ['max' => date('Y-m-d')]);

echo form_time('start_time', $start_time);
echo form_time('appointment', $appointment, ['step' => '900']); // 15-min intervals

echo form_datetime_local('event_start', $event_start);
echo form_datetime_local('deadline', $deadline, ['required' => 'required']);

echo form_month('billing_month', $billing_month);
echo form_month('report_month', $report_month, ['max' => date('Y-m')]);

echo form_week('work_week', $work_week);
echo form_week('schedule_week', $schedule_week, ['required' => 'required']);

Native HTML5 Inputs: Date and time functions use browser-native pickers. Values are always submitted in ISO 8601 format regardless of how the browser displays them to the user.

Textarea and Dropdown

Function Parameters Returns
$name, $value, $attributes <textarea> element
$name, $options, $selected, $attributes <select> element

Examples

View File
echo form_textarea('bio', $bio);
echo form_textarea('description', $description, ['rows' => '10']);

$options = ['1' => 'Option One', '2' => 'Option Two'];
echo form_dropdown('choice', $options, $selected_choice);

Checkboxes and Radio Buttons

Function Parameters Returns
$name, $value, $checked, $attributes <input type="checkbox">
$name, $value, $checked, $attributes <input type="radio">

Examples

View File
echo form_checkbox('subscribe', 1, $subscribe);
echo form_checkbox('active', 1, $active, ['id' => 'active-checkbox']);

echo form_radio('status', 'active', $status_active);
echo form_radio('status', 'inactive', $status_inactive);

Labels and Buttons

Function Parameters Returns
$label_text, $attributes <label> element
$name, $value, $attributes <button type="submit">
$name, $value, $attributes <button> element

Examples

View File
echo form_label('Email Address');
echo form_label('Username', ['for' => 'username-field']);

echo form_submit('submit', 'Save');
echo form_submit('submit', 'Delete', ['class' => 'danger']);

echo form_button('action', 'Click Me');

Data Retrieval

Function Parameters Returns
$field, $clean_up, $cast_numeric Field value, array, or empty string

Examples

PHP
$username = post('username');
$email = post('email', true);
$quantity = post('quantity', true, true);
$all_data = post();
$all_clean = post(true);

Validation Error Display

Function Parameters Returns
$first_arg, $closing_html HTML error messages or JSON

Examples

View File
<?= validation_errors() ?>
<?= validation_errors('<div class="error">', '</div>') ?>
<?= validation_errors('email') ?>
PHP
// In API controller
validation_errors(422); // Returns JSON with 422 status code

Common Attribute Examples

All Input Types

['placeholder' => 'Enter text...']
['required' => 'required']
['maxlength' => '100']
['autocomplete' => 'off']
['id' => 'field-id']
['readonly' => 'readonly']
['disabled' => 'disabled']

Number Inputs

['min' => '1', 'max' => '100', 'step' => '1']

Date and Time Inputs

// Date constraints
['min' => '2025-01-01', 'max' => '2025-12-31']

// Time intervals (step in seconds)
['step' => '900'] // 15 minutes
['step' => '1800'] // 30 minutes
['step' => '3600'] // 1 hour

// DateTime constraints
['min' => '2025-12-27T09:00', 'max' => '2025-12-27T17:00']

Textareas

['rows' => '10', 'cols' => '50']

Forms

['method' => 'get']
['class' => 'highlight-errors']
['data-validate' => 'true']

Complete Form Example

View File
<?php
echo form_open('users/submit');

echo form_label('Full Name');
echo form_input('full_name', $full_name, ['placeholder' => 'John Smith']);

echo form_label('Email Address');
echo form_email('email', $email, ['required' => 'required']);

echo form_label('Birth Date');
echo form_date('birth_date', $birth_date, ['max' => date('Y-m-d')]);

echo form_label('Bio');
echo form_textarea('bio', $bio, ['rows' => '5']);

echo form_label('Country');
echo form_dropdown('country', $country_options, $selected_country);

echo '<label>';
echo form_checkbox('subscribe', 1, $subscribe);
echo ' Subscribe to newsletter';
echo '</label>';

echo form_submit('submit', 'Save');
echo form_close();
?>

All form helpers automatically escape attribute values for XSS protection.

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.

Leave Feedback About This Page