form_helper.php
This file is part of CodeIgniter 4 framework.
(c) CodeIgniter Foundation admin@codeigniter.com
For the full copyright and license information, please view the LICENSE file that was distributed with this source code.
Table of Contents
Functions
- form_open() : string
- Form Declaration
- form_open_multipart() : string
- Form Declaration - Multipart type
- form_hidden() : string
- Hidden Input Field
- form_input() : string
- Text Input Field. If 'type' is passed in the $type field, it will be used as the input type, for making 'email', 'phone', etc input fields.
- form_password() : string
- Password Field
- form_upload() : string
- Upload Field
- form_textarea() : string
- Textarea field
- form_multiselect() : string
- Multi-select menu
- form_dropdown() : string
- Drop-down Menu
- form_checkbox() : string
- Checkbox Field
- form_radio() : string
- Radio Button
- form_submit() : string
- Submit Button
- form_reset() : string
- Reset Button
- form_button() : string
- Form Button
- form_label() : string
- Form Label Tag
- form_datalist() : string
- Datalist
- form_fieldset() : string
- Fieldset Tag
- form_fieldset_close() : string
- Fieldset Close Tag
- form_close() : string
- Form Close Tag
- set_value() : array<int, string>|string
- Form Value
- set_select() : string
- Set Select
- set_checkbox() : string
- Set Checkbox
- set_radio() : string
- Set Radio
- validation_errors() : array<string, string>
- Returns the validation errors.
- validation_list_errors() : string
- Returns the rendered HTML of the validation errors.
- validation_show_error() : string
- Returns a single error for the specified field in formatted HTML.
Functions
form_open()
Form Declaration
form_open([string $action = '' ][, array<string|int, mixed>|string $attributes = [] ][, array<string|int, mixed> $hidden = [] ]) : string
Creates the opening portion of the form.
Parameters
- $action : string = ''
-
the URI segments of the form destination
- $attributes : array<string|int, mixed>|string = []
-
a key/value pair of attributes, or string representation
- $hidden : array<string|int, mixed> = []
-
a key/value pair hidden data
Return values
stringform_open_multipart()
Form Declaration - Multipart type
form_open_multipart([string $action = '' ][, array<string|int, mixed>|string $attributes = [] ][, array<string|int, mixed> $hidden = [] ]) : string
Creates the opening portion of the form, but with "multipart/form-data".
Parameters
- $action : string = ''
-
The URI segments of the form destination
- $attributes : array<string|int, mixed>|string = []
-
A key/value pair of attributes, or the same as a string
- $hidden : array<string|int, mixed> = []
-
A key/value pair hidden data
Return values
stringform_hidden()
Hidden Input Field
form_hidden(array<string|int, mixed>|string $name[, array<string|int, mixed>|string $value = '' ][, bool $recursing = false ]) : string
Generates hidden fields. You can pass a simple key/value string or an associative array with multiple values.
Parameters
- $name : array<string|int, mixed>|string
-
Field name or associative array to create multiple fields
- $value : array<string|int, mixed>|string = ''
-
Field value
- $recursing : bool = false
Return values
stringform_input()
Text Input Field. If 'type' is passed in the $type field, it will be used as the input type, for making 'email', 'phone', etc input fields.
form_input([array<string|int, mixed>|string $data = '' ][, string $value = '' ][, array<string|int, mixed>|object|string $extra = '' ][, string $type = 'text' ]) : string
Parameters
- $data : array<string|int, mixed>|string = ''
- $value : string = ''
- $extra : array<string|int, mixed>|object|string = ''
-
string, array, object that can be cast to array
- $type : string = 'text'
Return values
stringform_password()
Password Field
form_password([array<string|int, mixed>|string $data = '' ][, string $value = '' ][, array<string|int, mixed>|object|string $extra = '' ]) : string
Identical to the input function but adds the "password" type
Parameters
- $data : array<string|int, mixed>|string = ''
- $value : string = ''
- $extra : array<string|int, mixed>|object|string = ''
-
string, array, object that can be cast to array
Return values
stringform_upload()
Upload Field
form_upload([array<string|int, mixed>|string $data = '' ][, string $value = '' ][, array<string|int, mixed>|object|string $extra = '' ]) : string
Identical to the input function but adds the "file" type
Parameters
- $data : array<string|int, mixed>|string = ''
- $value : string = ''
- $extra : array<string|int, mixed>|object|string = ''
-
string, array, object that can be cast to array
Return values
stringform_textarea()
Textarea field
form_textarea([array<string|int, mixed>|string $data = '' ][, string $value = '' ][, array<string|int, mixed>|object|string $extra = '' ]) : string
Parameters
- $data : array<string|int, mixed>|string = ''
- $value : string = ''
- $extra : array<string|int, mixed>|object|string = ''
-
string, array, object that can be cast to array
Return values
stringform_multiselect()
Multi-select menu
form_multiselect([array<string|int, mixed>|string $name = '' ][, array<string|int, mixed> $options = [] ][, array<string|int, mixed> $selected = [] ][, array<string|int, mixed>|object|string $extra = '' ]) : string
Parameters
- $name : array<string|int, mixed>|string = ''
- $options : array<string|int, mixed> = []
- $selected : array<string|int, mixed> = []
- $extra : array<string|int, mixed>|object|string = ''
-
string, array, object that can be cast to array
Return values
stringform_dropdown()
Drop-down Menu
form_dropdown([array<string|int, mixed>|string $data = '' ][, array<string|int, mixed>|string $options = [] ][, array<string|int, mixed>|string $selected = [] ][, array<string|int, mixed>|object|string $extra = '' ]) : string
Parameters
- $data : array<string|int, mixed>|string = ''
- $options : array<string|int, mixed>|string = []
- $selected : array<string|int, mixed>|string = []
- $extra : array<string|int, mixed>|object|string = ''
-
string, array, object that can be cast to array
Return values
stringform_checkbox()
Checkbox Field
form_checkbox([array<string|int, mixed>|string $data = '' ][, string $value = '' ][, bool $checked = false ][, array<string|int, mixed>|object|string $extra = '' ]) : string
Parameters
- $data : array<string|int, mixed>|string = ''
- $value : string = ''
- $checked : bool = false
- $extra : array<string|int, mixed>|object|string = ''
-
string, array, object that can be cast to array
Return values
stringform_radio()
Radio Button
form_radio([array<string|int, mixed>|string $data = '' ][, string $value = '' ][, bool $checked = false ][, array<string|int, mixed>|object|string $extra = '' ]) : string
Parameters
- $data : array<string|int, mixed>|string = ''
- $value : string = ''
- $checked : bool = false
- $extra : array<string|int, mixed>|object|string = ''
-
string, array, object that can be cast to array
Return values
stringform_submit()
Submit Button
form_submit([array<string|int, mixed>|string $data = '' ][, string $value = '' ][, array<string|int, mixed>|object|string $extra = '' ]) : string
Parameters
- $data : array<string|int, mixed>|string = ''
- $value : string = ''
- $extra : array<string|int, mixed>|object|string = ''
-
string, array, object that can be cast to array
Return values
stringform_reset()
Reset Button
form_reset([array<string|int, mixed>|string $data = '' ][, string $value = '' ][, array<string|int, mixed>|object|string $extra = '' ]) : string
Parameters
- $data : array<string|int, mixed>|string = ''
- $value : string = ''
- $extra : array<string|int, mixed>|object|string = ''
-
string, array, object that can be cast to array
Return values
stringform_button()
Form Button
form_button([array<string|int, mixed>|string $data = '' ][, string $content = '' ][, array<string|int, mixed>|object|string $extra = '' ]) : string
Parameters
- $data : array<string|int, mixed>|string = ''
- $content : string = ''
- $extra : array<string|int, mixed>|object|string = ''
-
string, array, object that can be cast to array
Return values
stringform_label()
Form Label Tag
form_label([string $labelText = '' ][, string $id = '' ][, array<string|int, mixed> $attributes = [] ]) : string
Parameters
- $labelText : string = ''
-
The text to appear onscreen
- $id : string = ''
-
The id the label applies to
- $attributes : array<string|int, mixed> = []
-
Additional attributes
Return values
stringform_datalist()
Datalist
form_datalist(string $name, string $value, array<string|int, mixed> $options) : string
The
Parameters
- $name : string
- $value : string
- $options : array<string|int, mixed>
Return values
stringform_fieldset()
Fieldset Tag
form_fieldset([string $legendText = '' ][, array<string|int, mixed> $attributes = [] ]) : string
Used to produce
Parameters
- $legendText : string = ''
-
The legend text
- $attributes : array<string|int, mixed> = []
-
Additional attributes
Return values
stringform_fieldset_close()
Fieldset Close Tag
form_fieldset_close([string $extra = '' ]) : string
Parameters
- $extra : string = ''
Return values
stringform_close()
Form Close Tag
form_close([string $extra = '' ]) : string
Parameters
- $extra : string = ''
Return values
stringset_value()
Form Value
set_value(string $field[, array<int, string>|string $default = '' ][, bool $htmlEscape = true ]) : array<int, string>|string
Grabs a value from the POST array for the specified field so you can re-populate an input field or textarea
Parameters
- $field : string
-
Field name
- $default : array<int, string>|string = ''
-
Default value
- $htmlEscape : bool = true
-
Whether to escape HTML special characters or not
Return values
array<int, string>|stringset_select()
Set Select
set_select(string $field[, string $value = '' ][, bool $default = false ]) : string
Let's you set the selected value of a
Parameters
- $field : string
- $value : string = ''
- $default : bool = false
Return values
stringset_checkbox()
Set Checkbox
set_checkbox(string $field[, string $value = '' ][, bool $default = false ]) : string
Let's you set the selected value of a checkbox via the value in the POST array.
Parameters
- $field : string
- $value : string = ''
- $default : bool = false
Return values
stringset_radio()
Set Radio
set_radio(string $field[, string $value = '' ][, bool $default = false ]) : string
Let's you set the selected value of a radio field via info in the POST array.
Parameters
- $field : string
- $value : string = ''
- $default : bool = false
Return values
stringvalidation_errors()
Returns the validation errors.
validation_errors() : array<string, string>
First, checks the validation errors that are stored in the session.
To store the errors in the session, you need to use withInput()
with redirect()
.
The returned array should be in the following format: [ 'field1' => 'error message', 'field2' => 'error message', ]
Return values
array<string, string>validation_list_errors()
Returns the rendered HTML of the validation errors.
validation_list_errors([string $template = 'list' ]) : string
See Validation::listErrors()
Parameters
- $template : string = 'list'
Return values
stringvalidation_show_error()
Returns a single error for the specified field in formatted HTML.
validation_show_error(string $field[, string $template = 'single' ]) : string
See Validation::showError()
Parameters
- $field : string
- $template : string = 'single'