webCOMAND

form::field()

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

Prototype

string field(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).

Return

HTML code to represent the specified form field, including the label and value.  The default format is as follows, where {Field Title} is the Content Type Field Title (or Identifier if no Title) and <input> and <select> are the result of input().

<div class="field">
    <label>{Field Title}</label>
    <input type="text" name="{FieldIdentifier}" value="{value}" />
</div>
<div class="field">
    <label>{Field Title}</label>
    <select name="{FieldIdentifier}">
        <option value="{choices->value}">{choices->title}</option>
    </select> 
</div>

Example

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

Related

input()