src/System/Helpersform_helper.php

CodeIgniter

An open source application development framework for PHP

This content is released under the MIT License (MIT)

Copyright (c) 2014-2019 British Columbia Institute of Technology Copyright (c) 2019 CodeIgniter Foundation

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Functions

form_open()

form_open(string  $action = '', array|string  $attributes = array(), array  $hidden = array()) : string

Form Declaration

Creates the opening portion of the form.

Parameters

string $action

the URI segments of the form destination

array|string $attributes

a key/value pair of attributes, or string representation

array $hidden

a key/value pair hidden data

Returns

string

form_open_multipart()

form_open_multipart(string  $action = '', array|string  $attributes = array(), array  $hidden = array()) : string

Form Declaration - Multipart type

Creates the opening portion of the form, but with "multipart/form-data".

Parameters

string $action

The URI segments of the form destination

array|string $attributes

A key/value pair of attributes, or the same as a string

array $hidden

A key/value pair hidden data

Returns

string

form_hidden()

form_hidden(string|array  $name, string|array  $value = '', boolean  $recursing = false) : string

Hidden Input Field

Generates hidden fields. You can pass a simple key/value string or an associative array with multiple values.

Parameters

string|array $name

Field name or associative array to create multiple fields

string|array $value

Field value

boolean $recursing

Returns

string

form_input()

form_input(mixed  $data = '', string  $value = '', mixed  $extra = '', string  $type = 'text') : 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.

Parameters

mixed $data
string $value
mixed $extra
string $type

Returns

string

form_password()

form_password(mixed  $data = '', string  $value = '', mixed  $extra = '') : string

Password Field

Identical to the input function but adds the "password" type

Parameters

mixed $data
string $value
mixed $extra

Returns

string

form_upload()

form_upload(mixed  $data = '', string  $value = '', mixed  $extra = '') : string

Upload Field

Identical to the input function but adds the "file" type

Parameters

mixed $data
string $value
mixed $extra

Returns

string

form_textarea()

form_textarea(mixed  $data = '', string  $value = '', mixed  $extra = '') : string

Textarea field

Parameters

mixed $data
string $value
mixed $extra

Returns

string

form_multiselect()

form_multiselect(string  $name = '', array  $options = array(), array  $selected = array(), mixed  $extra = '') : string

Multi-select menu

Parameters

string $name
array $options
array $selected
mixed $extra

Returns

string

form_dropdown()

form_dropdown(mixed  $data = '', mixed  $options = array(), mixed  $selected = array(), mixed  $extra = '') : string

Drop-down Menu

Parameters

mixed $data
mixed $options
mixed $selected
mixed $extra

Returns

string

form_checkbox()

form_checkbox(mixed  $data = '', string  $value = '', boolean  $checked = false, mixed  $extra = '') : string

Checkbox Field

Parameters

mixed $data
string $value
boolean $checked
mixed $extra

Returns

string

form_radio()

form_radio(mixed  $data = '', string  $value = '', boolean  $checked = false, mixed  $extra = '') : string

Radio Button

Parameters

mixed $data
string $value
boolean $checked
mixed $extra

Returns

string

form_submit()

form_submit(mixed  $data = '', string  $value = '', mixed  $extra = '') : string

Submit Button

Parameters

mixed $data
string $value
mixed $extra

Returns

string

form_reset()

form_reset(mixed  $data = '', string  $value = '', mixed  $extra = '') : string

Reset Button

Parameters

mixed $data
string $value
mixed $extra

Returns

string

form_button()

form_button(mixed  $data = '', string  $content = '', mixed  $extra = '') : string

Form Button

Parameters

mixed $data
string $content
mixed $extra

Returns

string

form_label()

form_label(string  $label_text = '', string  $id = '', array  $attributes = array()) : string

Form Label Tag

Parameters

string $label_text

The text to appear onscreen

string $id

The id the label applies to

array $attributes

Additional attributes

Returns

string

form_datalist()

form_datalist(string  $name, string  $value, array  $options) : string

Datalist

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

string $name
string $value
array $options

Returns

string

form_fieldset()

form_fieldset(string  $legend_text = '', array  $attributes = array()) : string

Fieldset Tag

Used to produce

text. To close fieldset use form_fieldset_close()

Parameters

string $legend_text

The legend text

array $attributes

Additional attributes

Returns

string

form_fieldset_close()

form_fieldset_close(string  $extra = '') : string

Fieldset Close Tag

Parameters

string $extra

Returns

string

form_close()

form_close(string  $extra = '') : string

Form Close Tag

Parameters

string $extra

Returns

string

set_value()

set_value(string  $field, string  $default = '', boolean  $html_escape = true) : string

Form Value

Grabs a value from the POST array for the specified field so you can re-populate an input field or textarea

Parameters

string $field

Field name

string $default

Default value

boolean $html_escape

Whether to escape HTML special characters or not

Returns

string

set_select()

set_select(string  $field, string  $value = '', boolean  $default = false) : string

Set Select

Let's you set the selected value of a