Embedding forms into your website
You can embed Form-Data forms into your website, in 4 different ways:
- Inline - embed the form seamlessly into your website
- Popup - the form will pop in the center of the screen
- Side panel - the form will slide in from the side of the screen
- Floating - the form will open as a floating widget that can be used while the content on the page is still accessible
If your site uses Vue, React, or Svelte, you can use one the respective components available for these frameworks.
This guide describes how to embed a form using javascript embed-tag. It also describes all the different options for embedding, which are also relevant for the framework components.
The embed code consists of 2 parts:
- The script loader
- Rendering code
The script loader
The script loader has to be placed just once in your website. It can be added into the <head>
section, or before the closing </body>
tag.
<script>
(function (j,o,y,e,m,b,d) {
j[e] ??= function () { (j[e].q ??= []).push(arguments) };
j[e].init ??= x => new Promise(s => j[e]('init', x||{}, s))
b = o.createElement(y), d = o.getElementsByTagName(y)[0];
b.id = e; b.src = m; b.async = 1; d.parentNode.insertBefore(b, d);
}(window, document, 'script', 'fd', 'https://embed.jolly.tools/widget.js'));
</script>
The only thing that you can change in this code snippet is the name of the global variable fd
. You should do that if it happens to conflict with another global variable with the same name that you have in your site.
Next, you need to call the init
command. Again, this has to be done just once, and therefore it is recommended to do it right after the loader script, in the same <script>
tag.
await fd.init({
// optionally pass this to see console logs
// debug: true
})
Rendering code
In order to render a form or a trigger (a floating button or a tab), you should call the render
command. This command can be called multiple times, depending on your needs.
render
command
const formApi = await fd.render({/*render options*/})
You should place this in the page that you want the widget to be rendered. It must be called after the script loader.
See ful render code sample in the quickstart guide
Let's look at the render options object:
url
- the full path to the form that you're loading. Make sure that the URL ends with/embed
id
- if you plan to call any other command, such asopen
orclose
, you should choose anid
so you can correlate to it later. Otherwise, you don't have to define it.params
- an Object with attributes that are being passed to the form as query params. Useful for pre-filled fields. For example, given the params:the form will pre-fill theparams: {
email: "Sara123@gmail.com"
}email
field. Note that params has to be a flat object with no sub-objects or arraysmode
- how you want to render the widget. Possible values are:inline
- will render the widget as part of the page itself. Can be appended to the body or to a defined element.popup
- will render as a popup in the center of the screen. Useful when you want the user's full attention to the content.sidebar
- will render as a sliding-in sidebar, either from the left or from the right.floating
- will render as a common chat widget. Works nicely with FAB trigger.
trigger
- define what type of trigger you want to render. Possible values:none
- don't render any trigger. This is the default. Use this if you embedinline
because then you don't need a trigger.fab
- Floating Action Button - floating at the bottom of the screen, on either side. Works especially well withfloating
embeds, but also looks nice with the other types.tab
- a side tab, sticky to either right or left. Can have custom text. This trigger is less intrusive thanfab
.
inline
- an Object with attributes that are used only whenmode
is set toinline
. Example:inline: {
selector: '.form-data',
maxWidth: '100vw',
width: '500px'
}selector
- css selector for the DOM element in which the entity will be rendered. Default isbody
which means the widget will be appended to the end of the page.width
- width of the widget, including the css unit. The default is100%
which means it will take the entire width of the container.maxWidth
- useful for mobile view. If you set thewidth
to somepx
number, you can set this value using another unit so the widget will not get wider than the screen. Default is100vw
which is the width of the window.
popup
- an Object with attributes that are used only whenmode
is set topopup
. Example:popup: {
zIndex: '999999',
transitionDuration: '250ms',
radius: '12px',
width: '800px',
height: '600px',
overlay: true,
closeButton: true
}zIndex
- if the popup appears below one of the elements on the page, you can set this property to a number that is higher than the zIndex of that element. Default is99999
. Can be set as a Number or a String.transitionDuration
- the amount of time the animation is playing, including the css unit. Default is300ms
radius
- the radius of the popup's corners, including the css unit. Default is8px
width
andheight
- the dimensions of the popup, including the css unit. On mobile popups are automatically set to take the full screen, regardless of this setting. If you want the popup to be relative to the window size, you can usevw
andvh
units, or even usecalc
. For example:// cover the entire window:
width: '100vw',
height: '100vh'
// cover the entire window, minus 15px margin:
width: 'calc(100vw - 30px)', // note the space around the minus sign
height: 'calc(100vh - 30px)'overlay
- a boolean that indicates whether an overlay should be rendered above the page, so that full attention is given to the popup. If set to true, you can customize the overlay using theoverlay
object property. See below.closeButton
- a boolean that indicates whether a close button should be rendered in the top-right corner of the popup. Default istrue
.
sidebar
- an Object with attributes that are used only whenmode
is set tosidebar
. Example:sidebar: {
side: 'right',
width: '600px',
transitionDuration: '250ms',
overlay: true,
zIndex: '999999',
closeButton: true
}side
- eitherleft
orright
. Default isright
.width
- The width of the sidebar, including the css unit. Default is600px
. On mobile the sidebar is rendered as full width, regardless of this setting.transitionDuration
- the amount of time the animation is playing, including the css unit. Default is300ms
.overlay
- a boolean that indicates whether an overlay should be rendered above the page, so that full attention is given to the sidebar. If set to true, you can customize the overlay using theoverlay
object property. See below.zIndex
- if the sidebar appears below one of the elements on the page, you can set this property to a number that is higher than the zIndex of that element. Default is99999
. Can be set as a Number or a String.closeButton
- a boolean that indicates whether a close button should be rendered in the corner of the sidebar. Default istrue
.
floating
- an Object with attributes that are used only whenmode
is set tofloating
. Example:floating: {
width: '600px',
maxWidth: '100vw'
overlay: true,
side: 'left',
zIndex: '99999',
transitionDuration: '500ms',
radius: '25px',
closeButton: true
}width
- width of the floating widget, including the css unit. Default is350px
.maxWidth
- useful for mobile view. If you set thewidth
to somepx
number, you can set this value using another unit so the widget will not get wider than the screen. Default is100vw
which is the width of the window.overlay
- a boolean that indicates whether an overlay should be rendered above the page, so that full attention is given to the sidebar. If set to true, you can customize the overlay using theoverlay
object property. See below.side
- eitherleft
orright
. Default isright
.zIndex
- if the floating widget appears below one of the elements on the page, you can set this property to a number that is higher than the zIndex of that element. Default is99999
. Can be set as a Number or a String.transitionDuration
- the amount of time the animation is playing, including the css unit. Default is300ms
.radius
- the radius of the widget's corners, including the css unit. Default is8px
closeButton
- a boolean that indicates whether a close button should be rendered in the corner of the widget. Default istrue
.
overlay
- an Object with attributes that are used only whenmode
is set tofloating
,popup
orsidebar
, and the respectiveoverlay
attribute is set totrue
. Example:overlay: {
zIndex: '999',
color: '#000',
opacity: 0.6,
closeOnClick: true,
transitionDuration: '300ms'
}zIndex
- if the overlay appears below one of the elements on the page, you can set this property to a number that is higher than the zIndex of that element. Default is999
. Can be set as a Number or a String. Must be lower than the zIndex of the widget.color
- a css color of the overlay, not including opacity. Default is#000
.opacity
- a Number between 0-1 that indicates the opacity of the overlay.0
means fully transparent and1
means opaque. Default is0.5
closeOnClick
- a boolean that indicates whether the widget should be closed when the overlay is clicked. Default is true.transitionDuration
- the amount of time the animation is playing, including the css unit. Default is300ms
.
fab
- an Object with attributes that are used only whentrigger
is set tofab
. Example:fab: {
background: '#86c3e8',
width: '80px',
zIndex: '999999',
color: '#ffffff',
onOpenMode: 'close', /* hide | close */
side: 'left', /* right | left */
icon: 'smilies',
iconSize: '50%',
iconOnly: true,
shadow: '0 0 10px rgba(0,0,0,0.3)'
}background
- the color of the button. WheniconOnly
is set totrue
, this color will be apparent only inclose
mode (seeonOpenMode
below).width
- the size of the button, including the css unit. Default is50px
zIndex
- if the floating widget appears below one of the elements on the page, you can set this property to a number that is higher than the zIndex of that element. Default is99999
. Can be set as a Number or a String.color
- the color of the close icon. Only used whenonOpenMode
is set toclose
onOpenMode
- defines the behavior of the button when the widget is opened. Possible values:close
- the button turns into a close button. The color of the button is set by thebackground
attribute, and the color of the icon is set by thecolor
attribute. This is the recommended mode when used in conjunction withfloating
widget.hide
- the button is hidden. This is the recommended mode when using in conjunction withpopup
orsidebar
mode. This is the default value.
side
- eitherleft
orright
. Default isright
. When used in conjunction withfloating
orsidebar
mode, it is recommended to use the same side as the widget.icon
- one of the named icons:hand-thumb-up
,hand-up-help
,smilies
,megaphone-black
,megaphone-white
,pencil-bubble-black
,pencil-bubble-white
,question-mark-balck
andquestion-mark-white
iconSize
- the size of the icon. Recommended using as a percentage of button size. Default is50%
. WheniconOnly
is set to true, this affects only the close-icon size.
tab
- an Object with attributes that are used only whentrigger
is set totab
. Example:tab: {
background: '#27bdf6',
borderRadius: '8px',
zIndex: '2000',
color: '#ffffff',
side: 'right', /* right | left */
label: 'Feedback',
bottom: '10%'
}background
- the color of the tab. Default is#00a3dd
, which is light blue.borderRadius
- the radius of the tab's corners, including the css unit. Default is3px
.zIndex
- if the tab appears below one of the elements on the page, you can set this property to a number that is higher than the zIndex of that element. Default is99999
. Can be set as a Number or a String.color
- the color of the text. Default is#ffffff
.side
- eitherleft
orright
. Default isright
. When used in conjunction withfloating
orsidebar
mode, it is recommended to use the same side as the widget.label
- the text that appears on the tab. Default isFeedback
.bottom
- the distance of the tab from the bottom of the screen. Default is20%
.
Custom triggers
If you prefer creating your own trigger that will show and hide the form, you should use the open
, close
and toggle
commands:
// This will not actually render anything, but you still need to call it
const formApi = await fd.render({
url: '<YOUR_FORM_URL>/embed',
id: 'contactForm',
mode: 'sidebar',
params: {},
sidebar: {
side: 'right',
overlay: false,
width: '360px'
},
)
// Call these commands from your own custom button handler
formApi.open()
formApi.close()
formApi.toggle()
Notes:
- The
render
command does not have atrigger
option, and therefore no button or tab are being rendered - If you have an SPA, and the page that renders the form is being destroyed, you should call the
destory
command in order to avoid memory leak:formApi.destroy()