form_helper.php
This file is part of the 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
- 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() : string|array<string|int, string>
- Form Value
- set_select() : string
- Set Select
- set_checkbox() : string
- Set Checkbox
- set_radio() : string
- Set Radio
- parse_form_attributes() : string
- Parse the form attributes
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
string —form_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
string —form_hidden()
Hidden Input Field
form_hidden(string|array<string|int, mixed> $name[, string|array<string|int, mixed> $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 : string|array<string|int, mixed>
-
Field name or associative array to create multiple fields
- $value : string|array<string|int, mixed> = ''
-
Field value
- $recursing : bool = false
Return values
string —form_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([mixed $data = '' ][, string $value = '' ][, mixed $extra = '' ][, string $type = 'text' ]) : string
Parameters
- $data : mixed = ''
- $value : string = ''
- $extra : mixed = ''
- $type : string = 'text'
Return values
string —form_password()
Password Field
form_password([mixed $data = '' ][, string $value = '' ][, mixed $extra = '' ]) : string
Identical to the input function but adds the "password" type
Parameters
- $data : mixed = ''
- $value : string = ''
- $extra : mixed = ''
Return values
string —form_upload()
Upload Field
form_upload([mixed $data = '' ][, string $value = '' ][, mixed $extra = '' ]) : string
Identical to the input function but adds the "file" type
Parameters
- $data : mixed = ''
- $value : string = ''
- $extra : mixed = ''
Return values
string —form_textarea()
Textarea field
form_textarea([mixed $data = '' ][, string $value = '' ][, mixed $extra = '' ]) : string
Parameters
- $data : mixed = ''
- $value : string = ''
- $extra : mixed = ''
Return values
string —form_multiselect()
Multi-select menu
form_multiselect([mixed $name = '' ][, array<string|int, mixed> $options = [] ][, array<string|int, mixed> $selected = [] ][, mixed $extra = '' ]) : string
Parameters
- $name : mixed = ''
- $options : array<string|int, mixed> = []
- $selected : array<string|int, mixed> = []
- $extra : mixed = ''
Return values
string —form_dropdown()
Drop-down Menu
form_dropdown([mixed $data = '' ][, mixed $options = [] ][, mixed $selected = [] ][, mixed $extra = '' ]) : string
Parameters
- $data : mixed = ''
- $options : mixed = []
- $selected : mixed = []
- $extra : mixed = ''
Return values
string —form_checkbox()
Checkbox Field
form_checkbox([mixed $data = '' ][, string $value = '' ][, bool $checked = false ][, mixed $extra = '' ]) : string
Parameters
- $data : mixed = ''
- $value : string = ''
- $checked : bool = false
- $extra : mixed = ''
Return values
string —form_radio()
Radio Button
form_radio([mixed $data = '' ][, string $value = '' ][, bool $checked = false ][, mixed $extra = '' ]) : string
Parameters
- $data : mixed = ''
- $value : string = ''
- $checked : bool = false
- $extra : mixed = ''
Return values
string —form_submit()
Submit Button
form_submit([mixed $data = '' ][, string $value = '' ][, mixed $extra = '' ]) : string
Parameters
- $data : mixed = ''
- $value : string = ''
- $extra : mixed = ''
Return values
string —form_reset()
Reset Button
form_reset([mixed $data = '' ][, string $value = '' ][, mixed $extra = '' ]) : string
Parameters
- $data : mixed = ''
- $value : string = ''
- $extra : mixed = ''
Return values
string —form_button()
Form Button
form_button([mixed $data = '' ][, string $content = '' ][, mixed $extra = '' ]) : string
Parameters
- $data : mixed = ''
- $content : string = ''
- $extra : mixed = ''
Return values
string —form_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
string —form_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
string —form_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
string —form_fieldset_close()
Fieldset Close Tag
form_fieldset_close([string $extra = '' ]) : string
Parameters
- $extra : string = ''
Return values
string —form_close()
Form Close Tag
form_close([string $extra = '' ]) : string
Parameters
- $extra : string = ''
Return values
string —set_value()
Form Value
set_value(string $field[, string|array<string|int, string> $default = '' ][, bool $htmlEscape = true ]) : string|array<string|int, 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 : string|array<string|int, string> = ''
-
Default value
- $htmlEscape : bool = true
-
Whether to escape HTML special characters or not
Return values
string|array<string|int, string> —set_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
string —set_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. If Form Validation is active it retrieves the info from the validation class
Parameters
- $field : string
- $value : string = ''
- $default : bool = false
Return values
string —set_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. If Form Validation is active it retrieves the info from the validation class
Parameters
- $field : string
- $value : string = ''
- $default : bool = false
Return values
string —parse_form_attributes()
Parse the form attributes
parse_form_attributes(string|array<string|int, mixed> $attributes, array<string|int, mixed> $default) : string
Helper function used by some of the form helpers
Parameters
- $attributes : string|array<string|int, mixed>
-
List of attributes
- $default : array<string|int, mixed>
-
Default values