Form Helper Reference
Quick reference for all form helper functions in Trongate.
Form Tags
| Function |
Parameters |
Returns |
| form_open() |
$location, $attributes |
Opening <form> tag |
| form_open_upload() |
$location, $attributes |
Opening <form enctype="multipart/form-data"> |
| form_close() |
None |
CSRF token + </form> tag |
Examples
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 |
| form_input() |
text |
$name, $value, $attributes |
| form_email() |
email |
$name, $value, $attributes |
| form_password() |
password |
$name, $value, $attributes |
| form_number() |
number |
$name, $value, $attributes |
| form_search() |
search |
$name, $value, $attributes |
| form_hidden() |
hidden |
$name, $value, $attributes |
| form_file_select() |
file |
$name, $attributes |
Examples
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_hidden('user_id', $user_id);
echo form_file_select('document', ['accept' => '.pdf']);
Date and Time Input Fields
| Function |
Type |
Format |
Parameters |
| form_date() |
date |
YYYY-MM-DD |
$name, $value, $attributes |
| form_time() |
time |
HH:MM |
$name, $value, $attributes |
| form_datetime_local() |
datetime-local |
YYYY-MM-DDTHH:MM |
$name, $value, $attributes |
| form_month() |
month |
YYYY-MM |
$name, $value, $attributes |
| form_week() |
week |
YYYY-W## |
$name, $value, $attributes |
Examples
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 |
| form_textarea() |
$name, $value, $attributes |
<textarea> element |
| form_dropdown() |
$name, $options, $selected, $attributes |
<select> element |
Examples
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 |
| form_checkbox() |
$name, $value, $checked, $attributes |
<input type="checkbox"> |
| form_radio() |
$name, $value, $checked, $attributes |
<input type="radio"> |
Examples
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 |
| form_label() |
$label_text, $attributes |
<label> element |
| form_submit() |
$name, $value, $attributes |
<button type="submit"> |
| form_button() |
$name, $value, $attributes |
<button> element |
Examples
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 |
| post() |
$field, $clean_up, $cast_numeric |
Field value, array, or empty string |
Examples
$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 |
| validation_errors() |
$first_arg, $closing_html |
HTML error messages or JSON |
Examples
<?= validation_errors() ?>
<?= validation_errors('<div class="error">', '</div>') ?>
<?= validation_errors('email') ?>
// 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
<?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.