input() form()
A form row with an <input> of any type; text(), email(), number() and the other inputs are input() with a type.
form()->input($name, $desc = '', $extra = [], $replace = [])Options
| Option | Meaning |
|---|---|
type | Input type; default text. |
desc | Label (also the second argument); default the name with _ as spaces; the placeholder too unless placeholder is set. |
value | Value; default $replace[name], then selected, then the form option selected. |
placeholder, title, maxlength, size, pattern, min, max, step, autocomplete, autofocus, accept | HTML attributes. |
required, disabled, readonly | HTML attributes; required also comes from a required validation rule. |
class, class_add, style, id | class replaces form-control, class_add adds to it. |
sizing | sm or lg: input-sm (Bootstrap 3) / form-control-sm (5). |
prepend, append, prepend_html, append_html | Text or HTML in an input group before / after the field. |
tip, inline_help, help_before | Help icon with a popover; help text under the field; help above it. |
edit_link, link_name | A link next to the field (a URL or a $replace key). |
no_label, stacked, wide, floating | No label; inside a row_start(); full width; Bootstrap 5 floating label. |
class_add_form_group, class_add_label, class_add_controls | Classes of the row parts. |
validate | Rules of this field, as in validate(). |
display_func | Callback fn ($extra, $replace, $form); false hides the row. |
data-*, attr | Data attributes. |
Example
Code
return form(['sku' => 'LAMP-01'])
->input('sku', 'SKU', ['maxlength' => 12, 'pattern' => '[A-Z0-9-]+', 'tip' => 'Upper case letters, digits and -'])
->input('weight', ['type' => 'number', 'step' => '0.1', 'append' => 'kg', 'sizing' => 'sm'])
->input('note', ['inline_help' => 'Shown on the packing slip', 'placeholder' => 'Optional']);Notes
- The second argument may be the options array:
input('name', ['desc' => ...]). - The value is HTML-escaped and its template braces become entities.
Bootstrap 3 and 5
Bootstrap 3: form-group rows, label col-md-3, input-group-addon; Bootstrap 5: mb-3 row, col-form-label, input-group-text, errors as is-invalid + invalid-feedback.
See also: form/text, form/html5_inputs, html/input