If you use any of the form helper functions listed on this page, the form values will be automatically escaped, so there is no need to call this function. Use it only if you are creating your own form elements.

Available Functions

The following functions are available:

form_open([$action = ''[, $attributes = ''[, $hidden = array()]]])

Parameters:

$action (string) – Form action/target URI string

$attributes (array) – HTML attributes

$hidden (array) – An array of hidden fields’ definitions

Returns:

An HTML form opening tag

Return type:

string

Creates an opening form tag with a base URL built from your config preferences. It will optionally let you add form attributes and hidden input fields, and will always add the accept-charset attribute based on the charset value in your config file.

The main benefit of using this tag rather than hard coding your own HTML is that it permits your site to be more portable in the event your URLs ever change.

Here’s a simple example:

echo form_open('email/send');

The above example would create a form that points to your base URL plus the “email/send” URI segments, like this:

$selected (array) – List of fields to mark with the selected attribute

$extra (mixed) – Extra attributes to be added to the tag either as an array or a literal string

Returns:

An HTML dropdown select field tag

Return type:

string

Lets you create a standard drop-down field. The first parameter will contain the name of the field, the second parameter will contain an associative array of options, and the third parameter will contain the value you wish to be selected. You can also pass an array of multiple items through the third parameter, and CodeIgniter will create a multiple select for you.

$selected (array) – List of fields to mark with the selected attribute

$extra (mixed) – Extra attributes to be added to the tag either as an array or a literal string

Returns:

An HTML dropdown multiselect field tag

Return type:

string

Lets you create a standard multiselect field. The first parameter will contain the name of the field, the second parameter will contain an associative array of options, and the third parameter will contain the value or values you wish to be selected.

The parameter usage is identical to using form_dropdown() above, except of course that the name of the field will need to use POST array syntax, e.g. foo[].

Similar to other functions, you can submit an associative array in the first parameter if you prefer to set your own attributes. The third parameter lets you add extra data to your form, like JavaScript.

form_reset([$data = ''[, $value = ''[, $extra = '']]])

Parameters:

$data (string) – Button name

$value (string) – Button value

$extra (mixed) – Extra attributes to be added to the tag either as an array or a literal string

Returns:

An HTML input reset button tag

Return type:

string

Lets you generate a standard reset button. Use is identical to form_submit().

form_button([$data = ''[, $content = ''[, $extra = '']]])

Parameters:

$data (string) – Button name

$content (string) – Button label

$extra (mixed) – Extra attributes to be added to the tag either as an array or a literal string

Returns:

An HTML button tag

Return type:

string

Lets you generate a standard button element. You can minimally pass the button name and content in the first and second parameter:

Permits you to set the value of an input form or textarea. You must supply the field name via the first parameter of the function. The second (optional) parameter allows you to set a default value for the form. The third (optional) parameter allows you to turn off HTML escaping of the value, in case you need to use this function in combination with i.e. form_input() and avoid double-escaping.

If you’ve loaded the Form Validation Library and have set a validation rule for the field name in use with this helper, then it will forward the call to the Form Validation Library‘s own set_value() method. Otherwise, this function looks in $_POST for the field value.

set_select($field[, $value = ''[, $default = FALSE]])

Parameters:

$field (string) – Field name

$value (string) – Value to check for

$default (string) – Whether the value is also a default one

Returns:

‘selected’ attribute or an empty string

Return type:

string

If you use a <select> menu, this function permits you to display the menu item that was selected.

The first parameter must contain the name of the select menu, the second parameter must contain the value of each item, and the third (optional) parameter lets you set an item as the default (use boolean TRUE/FALSE).

If you are using the Form Validation class, you must always specify a rule for your field, even if empty, in order for the set_*() functions to work. This is because if a Form Validation object is defined, the control for set_*() is handed over to a method of the class instead of the generic helper function.

form_error([$field = ''[, $prefix = ''[, $suffix = '']]])

Parameters:

$field (string) – Field name

$prefix (string) – Error opening tag

$suffix (string) – Error closing tag

Returns:

HTML-formatted form validation error message(s)

Return type:

string

Returns a validation error message from the Form Validation Library, associated with the specified field name. You can optionally specify opening and closing tag(s) to put around the error message.

Allows you to safely use HTML and characters such as quotes within form elements without breaking out of the form.

Note

If you use any of the form helper functions listed in this page the form values will be prepped automatically, so there is no need to call this function. Use it only if you are creating your own form elements.

Note

This function is DEPRECATED and is just an alias for common functionhtml_escape() - please use that instead.