Form Embedding
How to embed a Form.io form within your application.
Last updated
How to embed a Form.io form within your application.
Last updated
The Form.io platform is an advanced JavaScript platform that enables Developers and Non-Developers alike to build forms and easily embed them within their own applications and websites. There are multiple ways that we offer the embedding of our forms, ranging from the non-technical, yet powerful, Quick Inline Embedding, to the more advanced JavaScript embedding. All of the Form.io components are embeddable, and this documentation will outline all the ways you can embed a form.
By far the easiest way to embed a form within your application is to use the Quick Inline Embedding mechanism. This provides a one-line code snippet that is capable of embedding a form directly inline within a browser page. To embed a form, you simply copy and paste the following code directly in the place on your HTML website you would like to see the form.
You can change the form you embed by simply changing the https://examples.form.io/example
string to the URL of your Form. This can be found by navigating to your form, and then clicking on the "link" symbol next to the form name as shown below.
If you wish to have an easy interface to configure this Embed, then please check out our online Quick Inline Embed Configurator.
You can also click on the Embed tab within every form so see an interface that allows you to easily configure this embed code so that you can copy and paste this into your application. There are a number of advanced options that you can use to configure how the embedded form behaves by adding Query parameters on the "src" URL of the script tag. For example, if you wish to load all the dependent CSS libraries along with the embed code, you can add the following to the end of the embed src like so.
Here is a list of all available options you can pass into this embed script along with more advanced functionality.
The following is a list of query parameters that can be provided to the Quick Inline Embed src string as shown in the example above.
In addition to being able to control the Quick Inline Embed through the use of parameters, you can also control the embedding through a use of a configuration that is added before the inline embed code. This code uses the global FormioConfig to tell the embedding script how you would like to inject within the form rendering process. The following shows an example of adding an after render handler to trigger once the form has finished rendering.
The following parameters can be used within the FormioConfig variable to control the embedded flow.
FormioConfig.before
This is a callback that is executed before the Form is rendered. This provides a good opportunity to make modifications to the Formio
renderer class as well as the configurations that are going to be passed to the renderer before the rendering occurs.
Example 1: Extend a method for a component.
This next example shows how a method within a component can be extended or overridden to provide custom functionality.
This next example uses the template system to modify the "input" template to provide a wrapper around all inputs rendered by the renderer. All templates can be found by going to https://github.com/formio/formio.js/tree/master/src/templates/bootstrap. This example shows how we can add a wrapper around all of the inputs within the renderer.
FormioConfig.after
This is a callback that is called after the form is done rendering. This is useful if you wish to register for certain form events and then perform actions based on those events, like so.
Example:
FormioConfig.config
This allows you to alter the Renderer configuration that is passed into the Formio.createForm
method. This is useful if you wish to provide a number of translations into the renderer like so.
Example:
FormioConfig.form
and FormioConfig.submission
The form
and submission
configuration allows you to provide the form or submission in JSON format to the renderer. If the form
is provided, then the src is no longer required and renders the form in JSON format. If the submission
is provided, then it is used to automatically populate the form with that submission data.
Example:
FormioConfig.libs
This configuration allows you to configure the URL for all the libs that are loaded within the renderer using the libs query parameter. The libs are defined and can be overridden, as follows.
The Form.io Form Viewer can be used to embed forms using iframes. It contains a special library called Seamless which will auto resize the iframe to the size of the form within the Parent page (the one doing the embedding). You can change the form to embed mode using the iframe=1
parameter on the URL, which is what is used within the {{ site.formio }} embed code as follows.
JavaScript Embedding is covered in great detail in the Form Renderer section of our help documentation.
Form Builder embedding is covered in great detail in the Form Builder section of our help documentation.
Form.io also supports embedding a form in many UI frameworks such as Angular, React, and Vue. These are discussed in great detail in the Frameworks section.
Parameter
Description
Default
src
(Required) The form url you wish to embed. If you use the form parameter, then this parameter is not required.
libs
Used to load all dependent CSS libraries to render the form. This also renders the form within a ShadowDOM which isolates the CSS and rendering of the form so that no outside styles will collide with the form. This is ideal if you wish to embed a form within a CMS such as Wordpress or Drupal. Set to "true" if you wish to enable this feature.
false
template
This determines the CSS template to use when rendering the form. The available templates are as follows.
- [empty]: Render the form in the default Bootstrap 4 template
- uswds: Render the form in USWDS template
- semantic: Render the form in the Semantic template.
class
The default "wrapper" class to include on the outside element of the rendered form.
formio-form-wrapper
project
The Project this form is associated with. This is needed along with the "base" parameter if you are planning on uploading files. This is because the renderer needs to determine the correct project url to upload the file against. Example: "https://examples.form.io" for our Hosted platform.
base
The API base for this Form.io platform behind the form. For example: "https://api.form.io" is the value for our Hosted platform.
submit
The endpoint you would like to POST the submission toward. This allows you to send the submission to other forms, or other endpoints other than the default "form" submission endpoint.
debug
Enable debug mode. Adds a number of console.log records to the browser on how this form is progressing through the embedding code.
false
redirect
The URL you would like to redirect to after they have finished submitting the form. For example, you could provide a "thank you" page URL as the value of this parameter.
return
Alias of "redirect"
script
This allows you to change the location of the formiojs renderer script.
style
This allows you to change the location of the formiojs renderer style