Embedding forms

Last updated:

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

Installation of the Formcentric client

As a first step, install the Formcentric client in your project:



If you want to include local SCSS files from a theme, you will also require SASS:


Angular integration via the SDK

Embedding uses the function mount() from @formcentric/client. As there is no official Angular component at the moment, we recommend creating a small, project-specific Angular wrapper component.

A potential implementation could look as follows:

formcentric.component.ts:


formcentric.component.html:


Using the component:


Including a local theme

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

Import the styles from the selected theme into src/styles.scss, for example:


Then import the JavaScript templates from the theme into your Angular application – into main.ts, for example, or into your local wrapper component:


Then extend the mount() configuration:



Please note:

  1. The theme styles must be loaded by your application itself.
  2. The JavaScript templates for the theme must also be imported locally.
  3. The values skipThemeLoad: true and skipTemplatesLoad: true are used to prevent the same resources also being loaded at runtime.


If you want to pass theme variables directly, you can set these as extra values in the configuration:


Return value and lifecycle

mount() returns an instance with lifecycle methods. This can be used for the targeted control of the embedded form.

Example:


Note the following:

  1. ready is triggered as soon as the initialisation has been successfully completed.
  2. reload() re-initialises the form in the same container.
  3. stop() terminates the running instance but leaves the target element in the DOM.
  4. unmount() removes the form and performs a full cleanup for the instance.

Re-initialisation and configuration changes

The SDK integration is restart-based. Configuration values are applied on initialisation and not carried across live to a running instance automatically.

If you change configuration values, the embedding should be re-established explicitly – by using a controlled unmount() followed by another mount(), for example.

For Angular, we recommend using your own input like remountKey, which triggers a targeted re-initialisation.

Note the following:

  1. Changes to remountKey should trigger a re-initialisation.
  2. Changes to embedId or formDefinition should also lead to a repeat embedding.
  3. In cases where handover between instances is desired, embedId should remain stable.
  4. For other configuration changes, the component should be given a controlled remount.

Events and troubleshooting

For simple integration projects, optional callbacks can be used directly in the configuration:

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

Example:


If you are using your own Angular wrapper component, these callbacks can also be forwarded externally via @Output() events – such as ready and error, for example.

Feedback