Embedding forms

Last updated:

This article explains how to embed Formcentric forms into a website.

Installation

As a first step, install the React component in your project:


If you want to use additional theme resources from the Formcentric client package, you can also install (optional):


If you want to include local SCSS files from a theme, you will also require SASS – e.g. with Vite:


Formcentric React component

Embedding uses the component FormcentricForm. The configuration is passed using props: data-fc-* attributes and a global initialisation call are not necessary for React integration.

A simple example:


Common defaults

Alongside the props on the individual FormcentricForm, React also supports two other levels for common defaults:

Source Scope Priority Description
browser-global defaults via über configure(...) or window.formcentric Entire browser page Low Read as defaults by the underlying SDK mount
FormcentricConfigProvider React subtree Medium Returns subtree-wide defaults for all FormcentricForm components underneath
Props ON FormcentricForm Individual form High Override browser globals and provider defaults


Note the following:

Topic Principle
Nested providers
Multiple FormcentricConfigProvider are combined together. Inner providers override outer values.
Object values
requestHeaders, themeVariables and configuration are combined together. If keys are identical, the nearer/local configuration wins.
Remount behaviour
Changes to provider defaults or browser-global defaults do not automatically affect forms already running. For a running instance, remountKey must also be changed or the component must be re-mounted.
Static only
dynamicInit is not a React prop and has no effect in the case of component-based mounts.

The full list of the common keys and their semantics is given in the main Formcentric Client (General) documentation.

In particular, the following are not envisaged as common defaults: embedId, formDefinition, vars, params, refs, formName, instanceId, conflictBehavior, remountKey, containerProps, onReady and onError.


Example with FormcentricConfigProvider:


For browser-global defaults outside of React-specific code, configure(...) from @formcentric/client can also be used.

Including a local theme

Theme resources can be integrated directly into the application as SCSS and JavaScript.

Please note that the application should be configured so that it can use SCSS. With Vite, all you need to do is install SASS:


Following this step, you import the styles for your selected theme into your own index.scss file:


You then import the theme files into your React application:


If you want to pass theme variables directly, you can set these as an extra prop:


Re-initialisation and prop changes

The React component is envisaged as an integration bridge and not as a fully controlled React widget. Most props only take effect when the form is initialised.

If configuration values change at runtime, the form should be explicitly re-initialised. The prop remountKey is available for this purpose.


Example:


Events and troubleshooting

For simple integration projects, optional callbacks can be used:

  1. onReady: is called after successful initialisation
  2. onError:is called after initialisation errors or runtime errors

Example:


onReady signals that the initialisation has been successfully completed. However, this is not a cast-iron guarantee of an “initial visible render timestamp” for the form.

Feedback