CodeIgniter v4.5 API

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
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(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
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([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
string

form_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
string

form_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
string

form_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
string

form_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
string

form_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
string

form_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
string

form_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
string

form_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
string

form_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
string

form_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
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 element specifies a list of pre-defined options for an element. Users will see a drop-down list of pre-defined options as they input data. The list attribute of the element, must refer to the id attribute of the element.

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

text. To close fieldset use form_fieldset_close()

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[, 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>|string

set_select()

Set Select

set_select(string $field[, string $value = '' ][, bool $default = false ]) : string

Let's you set the selected value of a