webCOMAND

form::input()

Return HTML code to represent a form field input specified by Content Type Field or Field Identifier.

Prototype

string input(mixed $field, array $options = [])

Parameters

  • field - A Content Type Field object or Field Identifier string.
  • options - The following optional key/value pairs:
    • attributes - An associative array of <input> or <select> attributes to override and/or add to the defaults.  If an attribute value is set to NULL, the attribute will be added without a value.
    • option_title - Field Identifier of the field to use when this field will produce a drop-down.  If the options are based on a content type (ie. a forward reference field or Data Type with Location), any field of the corresponding Content Type can be used.  If the options are based on  name to use
    • option_value - Similar to option_title above, but to determine the value.
    • custom_options - An array of associative arrays each with optional 'title', 'value', and 'object' keys.  These custom options will be merged into the standard choices alphabetically, unless custom_options_merge is specified.  If a title or value is not provided, an empty string will be assumed.
    • custom_options_merge - Change how custom_options are merged into the standard choices.  Options are 'prepend', 'append' and 'alpha' (default).
    • expanded - If TRUE, choices will be expressed as individual checkbox inputs for list fields and radio inputs for single selection field.  If FALSE, a <select> with <options> will be used.  If not specified (default), the Field's Expanded option will be used, where Auto and Collapsed = FALSE, and Expanded = TRUE.
    • no_fieldset - If TRUE, the typical <fieldset> tag will not surround expanded inputs (see previous option).

Return

HTML code to represent the specified form field input and current value.  The appropriate input, select or other HTML form element will be used based on the field's Field Type.

Example Text Line Field

<input type="text" name="{FieldIdentifier}" value="{value}" />

Example Text Line Field with Choices

<select name="{FieldIdentifier}">
    <option value="{choices->value}">{choices->title}</option>
</select> 

Example

$repo = comand::repo();
$contact = $repo->new_object('Contact');
$form = new \io_comand_web\form($contact);
echo($form->input('Name'));

Related

field()