Reference

Field

A Field object represents one field instance on a form. This is different from the general idea of a field type; here, you are working with the actual field that is being rendered, inspected or processed.

Properties

id

The ID of this use of the field on a form. Submissions and browser code use this ID; definitionId identifies the shared field settings.

uid

The form-field instance UID. Copies and new imports receive new instance UIDs.

definitionId

The database ID of the field’s shared settings, called its definition internally. Synced fields share this value. It is not a key for reading submission values.

definitionUid

The unique identifier (UID) of the field’s shared settings. Stencils and form imports use it to preserve synced field relationships across environments.

label

The field label.

handle

The field handle.

reference

The stable field reference, when available.

type

The field type.

form

The Form this field belongs to.

required

Whether the field is required.

enabled

Whether the field is enabled.

instructions

The field instructions.

placeholder

The field placeholder, where supported.

defaultValue

The field default value, where supported.

settings

The field settings.

Methods

The methods below help you render fields and read their values. For implementing storage and value handling in your own field type, see Custom Field.

hasLabel()

Returns whether the field should render a label.

getHtmlId()

Returns the field’s HTML id value.

getHtmlName()

Returns the field’s HTML name value.

getContainerAttributes()

Returns attributes for the field container.

getInputAttributes()

Returns attributes for the field input, where applicable.

renderInput(form, value)

Returns the field's input HTML. This omits the surrounding label, validation rules and error container. Use craft.formie.renderField(form, field) when custom rendering needs a complete field.

getReferenceBlockHtml()

Returns the field’s reference-block HTML.

getParentField()

Returns the parent field for sub-fields and nested fields.

setParentField()

Sets the parent field for sub-fields and nested fields.

getValueAsString()

Returns a string representation of a submitted value.

getValueAsData()

Returns data that can be encoded as JSON: a single value for simple fields, or named parts or selected records for more complex fields.

getValueForExport()

Returns the value prepared for export.

getValueForReport()

Returns a single readable value for a report cell, including report exports. Call field.getValueForReport(value, submission, useOptionLabels) with the normalized field value and its submission. The optional useOptionLabels argument defaults to true; pass false to use stored option values. The default implementation uses the field's string representation. Fields can customize report output independently of structured export data.

Fields implementing verbb\formie\base\ReportSubfieldsInterface can also provide direct child columns through getReportSubfields(). See Report Subcolumns for the opt-in contract.

getValueForSummary()

Returns the value prepared for summary views.

getValueForReference()

Returns the value prepared for singular reference contexts.

getValueForReferenceBlock()

Returns the value prepared for reference-block rendering.