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

OptionMeaning
typeInput type; default text.
descLabel (also the second argument); default the name with _ as spaces; the placeholder too unless placeholder is set.
valueValue; default $replace[name], then selected, then the form option selected.
placeholder, title, maxlength, size, pattern, min, max, step, autocomplete, autofocus, acceptHTML attributes.
required, disabled, readonlyHTML attributes; required also comes from a required validation rule.
class, class_add, style, idclass replaces form-control, class_add adds to it.
sizingsm or lg: input-sm (Bootstrap 3) / form-control-sm (5).
prepend, append, prepend_html, append_htmlText or HTML in an input group before / after the field.
tip, inline_help, help_beforeHelp icon with a popover; help text under the field; help above it.
edit_link, link_nameA link next to the field (a URL or a $replace key).
no_label, stacked, wide, floatingNo label; inside a row_start(); full width; Bootstrap 5 floating label.
class_add_form_group, class_add_label, class_add_controlsClasses of the row parts.
validateRules of this field, as in validate().
display_funcCallback fn ($extra, $replace, $form); false hides the row.
data-*, attrData attributes.

Example

 
kg
Shown on the packing slip

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