Form
The Form component (forms) embeds a Markel Forms instance within the page. It reads structured form configuration data from the Layout Service response — including field definitions, metadata, session IDs, and anti-forgery tokens — serializes it to JSON, and initialises the markelForms.init() JavaScript client which renders the form dynamically on the front end.
Unlike most BSTools5 components, Form does not use a standard datasource template (Helium/Beryllium). Instead, the rendering reads its data from Sitecore Forms items that define the form structure, field types, validation rules, and submission actions. The component also supports optional Google Address Autocomplete integration via an API key configured in application settings.
Examples
Live Example
Below is a liveforms rendering. The component reads its form definition from the Sitecore Forms datasource, serializes the field structure to JSON, and passes it to markelForms.init() on the client. The form rendered below includes standard field types (text inputs, dropdowns, checkboxes) along with built-in validation and submission handling. Note that the form requires a valid Form Item ID datasource — without one, the container div will render empty.
Usage Notes
Notes
- The Form component does not use a standard datasource template (Helium/Beryllium). Its datasource is a Sitecore Forms item that defines the entire form structure including field types, validation rules, conditional logic, and submission actions.
- The rendering injects two scripts into the
BodyBottomsection:/assets/markel-forms.js(the shared forms library) and a per-instance initialisation call tomarkelForms.init(apikey, "", googlekey, null, jsonData, id). - The API Key used in the init call comes from
SitecoreOptions.ApiKeyand authenticates the form submission against the Layout Service. - The optional Google Address Autocomplete API Key is read from
BSTools5:GoogleAddressAutocompleteApiKeyin application configuration. When provided, address fields in the form will offer Google Places autocomplete. - The component serializes the entire form definition (fields, metadata, session ID, anti-forgery token, page item ID, context item ID) via
Json.Serialize(ReadFields<Form>())and passes the resulting JSON directly into the client-side initialiser. - Each form instance renders inside a unique
<div id="{htmlId}">container. The HTML ID is derived from the rendering’s unique identifier so multiple forms can coexist on the same page. - In Experience Editor, an
<edit-label>is shown reminding authors they may need to save the page to see the form render correctly. - Form validation, multi-step navigation, and conditional field visibility are handled entirely by the
markel-forms.jsclient library — no server-side round trips occur after initial load.
Control Properties
Control Properties
Rendering Parameters
| Parameter | Type | Description |
|---|---|---|
| HeadingSize | Droplink | Controls the heading level (h1–h6) used for the section title when the form is wrapped in a titled grid. |
| TextAlignment | Droplink | Sets the text alignment class for the form container. |
| HideTitleHeading | Checkbox | When checked, the section title above the form is visually hidden (sr-only). |
| Small / Medium / Large | Droplink | Bootstrap column width at each breakpoint for the form’s grid column. |
| OffsetSmall / OffsetMedium / OffsetLarge | Droplink | Column offset at each breakpoint. |
| PaddingTop / PaddingBottom / PaddingStart / PaddingEnd | Droplink | Spacing utilities applied to the form column. |
| AddClass | Single-Line Text | Additional CSS class(es) appended to the column wrapper for custom styling. |
Datasource Fields (Form Model)
| Field | Type | Description |
|---|---|---|
| htmlPrefix | String | Optional prefix applied to all rendered field HTML IDs to avoid collisions when multiple forms are on the same page. |
| formSessionId | Object | Identifies the current form session for multi-step forms and anti-replay protection. |
| formItemId | Object | The Sitecore item ID of the Forms definition item that drives the form’s structure. |
| pageItemId | Object | The item ID of the hosting page, used for contextual submission routing. |
| antiForgeryToken | Object | Server-generated token embedded in the form for CSRF protection on submission. |
| metadata | Object | Additional form metadata (tracking, analytics context, form version info). |
| fields | List<Field> | The ordered collection of form field definitions including type, label, validation rules, conditions, and default values. |
| contextItemId | String | The context item ID passed to submit actions for item-aware processing. |
Application Configuration
| Setting | Source | Description |
|---|---|---|
| SitecoreOptions:ApiKey | appsettings / env | The Sitecore API key used to authenticate form submissions against the Layout Service endpoint. |
| BSTools5:GoogleAddressAutocompleteApiKey | appsettings / env | Google Places API key enabling address autocomplete on supported form fields. Optional — when empty, autocomplete is disabled. |