Form Embedding
How to embed a Form.io form within your application.
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.

Quick Inline Embedding

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.
1
<script src="https://cdn.form.io/formiojs/formio.embed.js?src=https://examples.form.io/example"></script>
Copied!
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.
1
...?src=https://examples.form.io/example&libs=true"></script>
Copied!
Here is a list of all available options you can pass into this embed script along with more advanced functionality.

Quick Inline Embed Query Params

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.
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.
This url
style
This allows you to change the location of the formiojs renderer style
This url

Advanced Usage

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.
1
<script type="text/javascript">
2
window.FormioConfig = {
3
after: function(instance) {
4
instance.on('change', function(changed) {
5
// This is triggered every time something on the form changes.
6
console.log(changed);
7
});
8
}
9
};
10
</script>
11
<script src="https://cdn.form.io/formiojs/formio.embed.js?src=https://examples.form.io/example"></script>
Copied!
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.
1
<script type="text/javascript">
2
window.FormioConfig = {
3
before: function(Formio, element, config)
4
// Override the checkbox setValue method like so.
5
var setValue = Formio.Components.components.checkbox.prototype.setValue;
6
Formio.Components.components.checkbox.prototype.setValue = function(value) {
7
console.log('The checkbox value has been set!');
8
return setValue.call(this, value);
9
};
10
11
// This is the wrapper element for the renderer.
12
console.log(element);
13
14
// Override a configuration. Like forcing a language setting.
15
config.config.language = 'sp';
16
}
17
};
18
</script>
19
<script src="https://cdn.form.io/formiojs/formio.embed.js?src=https://examples.form.io/example"></script>
Copied!

Example 2: Modifying a template

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.
1
<script type="text/javascript">
2
window.FormioConfig = {
3
before: function(Formio, element, config) {
4
var inputForm = Formio.Templates.current.input.form;
5
Formio.Templates.current = {
6
input: {
7
form: (ctx) => {
8
return '<div class="input-wrapper">' + inputForm(ctx) + '</div>';
9
}
10
}
11
};
12
}
13
};
14
</script>
15
<script src="https://cdn.form.io/formiojs/formio.embed.js?src=https://examples.form.io/example&libs=true"></script>
Copied!

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:
1
<script type="text/javascript">
2
window.FormioConfig = {
3
after: function(instance) {
4
instance.on('change', function(changed) {
5
// This is triggered every time something on the form changes.
6
console.log(changed);
7
});
8
}
9
};
10
</script>
11
<script src="https://cdn.form.io/formiojs/formio.embed.js?src=https://examples.form.io/example"></script>
Copied!

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:
1
<script type="text/javascript">
2
window.FormioConfig = {
3
config: {
4
language: 'sp',
5
i18n: {
6
sp: {
7
'First Name': 'Nombre de pila',
8
'Last Name': 'Apellido'
9
},
10
ch: {
11
'First Name': '名字',
12
'Last Name': '姓'
13
}
14
}
15
}
16
};
17
</script>
18
<script src="https://cdn.form.io/formiojs/formio.embed.js?src=https://examples.form.io/example"></script>
Copied!

FormioConfig.form and FormioConfig.submission

The form and submission configuration allows you to provide the form or submission in JSON format into the renderer. If the form is provided, then the src is no longer required and renders the form as JSON format. If the submission is provided, then it is used to automatically populate the form with that submission data.
Example:
1
<script type="text/javascript">
2
window.FormioConfig = {
3
config: {
4
readOnly: true
5
},
6
form: {
7
components: [
8
{
9
type: 'textfield',
10
key: 'firstName',
11
label: 'First Name'
12
}
13
]
14
},
15
submission: {
16
data: {
17
firstName: 'Travis'
18
}
19
}
20
};
21
</script>
22
<script src="https://cdn.form.io/formiojs/formio.embed.js"></script>
Copied!

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.
1
<script type="text/javascript">
2
window.FormioConfig = {
3
libs: {
4
uswds: {
5
js: 'https://cdn.jsdelivr.net/npm/[email protected]/dist/js/uswds.min.js',
6
css: 'https://cdn.jsdelivr.net/npm/[email protected]/dist/css/uswds.min.css'
7
},
8
fontawesome: {
9
css: 'https://cdn.jsdelivr.net/npm/[email protected]/css/font-awesome.min.css'
10
},
11
bootstrap: {
12
css: 'https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css'
13
}
14
}
15
};
16
</script>
17
<script src="https://cdn.form.io/formiojs/formio.embed.js"></script>
Copied!

IFrame Embedding (fallback)

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.
1
<script type="text/javascript">(function a(d, w, u) {var h = d.getElementsByTagName("head")[0];var s = d.createElement("script");s.type = "text/javascript";s.src = "https://portal.form.io/lib/seamless/seamless.parent.min.js";s.onload = function b() {var f = d.getElementById("formio-form-57aa1d2a5b7a477b002717fe");if (!f || (typeof w.seamless === u)) {return setTimeout(b, 100);}w.seamless(f, {fallback:false}).receive(function(d, e) {});};h.appendChild(s);})(document, window);</script>
2
<iframe id="formio-form-57aa1d2a5b7a477b002717fe" style="width:100%;border:none;" height="600px" src="https://formview.io/#/examples/example?iframe=1&header=0"></iframe>
Copied!

JavaScript Embedding

JavaScript Embedding is covered in great detail in the Form Renderer section of our help documentation.

Form Builder Embedding

Form Builder embedding is covered in great detail in the Form Builder section of our help documentation.

Framework Embedding

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.

Last modified 3mo ago