Skip to main content
Formalingo

Embedding Documents

Embed Formalingo document signing pages on any website using iframes or the JavaScript SDK.

Embedding Documents

Document signing pages can be embedded on external websites using an iframe or the JavaScript SDK. By default, document signing pages allow embedding from any domain (no whitelist required).

Quick Start — iFrame

<iframe
  src="https://www.formalingo.com/d/SIGNER_TOKEN"
  width="100%"
  height="800"
  frameborder="0"
  style="border: none;"
></iframe>

Replace SIGNER_TOKEN with the signer's token from the submission response.

Quick Start — JavaScript SDK

<div id="my-document"></div>
<script src="https://www.formalingo.com/embed.js"></script>
<script>
  Formalingo.createDocument({
    container: '#my-document',
    documentUrl: 'https://www.formalingo.com/d/SIGNER_TOKEN',
    onSigned: function(data) {
      console.log('Document signed!', data);
    },
    onReady: function(data) {
      console.log('Document loaded', data);
    }
  });
</script>

The SDK automatically resizes the iframe to fit the document content.

SDK Options Reference

Formalingo.createDocument(options)
NameTypeDescription
containerstring | HTMLElementCSS selector or DOM element where the document will be rendered. Required.
documentUrlstringFull document signing URL (e.g. https://www.formalingo.com/d/TOKEN). Required.
heightnumberInitial iframe height in pixels. Default: 800.
autoResizebooleanAuto-resize iframe based on document content height. Default: true.
onReadyfunction(payload)Called when the document is fully loaded and interactive.
onSignedfunction(payload)Called when the signer completes signing.
onFieldAnsweredfunction(payload)Called when a field value changes.
onErrorfunction(payload)Called when a document error occurs (e.g. submission failure).
onHeightChangefunction(payload)Called when the document content height changes.

The createDocument method returns an object with:

  • iframe — the HTMLIFrameElement reference
  • destroy() — removes the iframe and cleans up event listeners

postMessage Events

Embedded documents emit events to the parent window via postMessage. All events are prefixed with formalingo. and have this structure:

{
  "type": "formalingo.eventName",
  "payload": { ... }
}

Event Reference

Events
NameTypeDescription
formalingo.documentLoaded{ documentId, title }The document signing component has mounted.
formalingo.documentReady{ documentId, title, fieldCount, signerRole }The document is fully loaded with all fields ready for interaction.
formalingo.fieldAnswered{ documentId, fieldId, fieldType, completedFields, totalFields }A field value was changed. Does not include the field value for privacy.
formalingo.documentSigned{ documentId, signerRole }The signer successfully completed signing.
formalingo.documentHeight{ documentId, height }The document content height changed (used for auto-resize).
formalingo.documentError{ documentId, error, code }An error occurred during the signing process.

Listening to Events Without the SDK

window.addEventListener('message', function(event) {
  var data = event.data;
  if (!data || !data.type || data.type.indexOf('formalingo.') !== 0) return;

  switch (data.type) {
    case 'formalingo.documentSigned':
      console.log('Document signed:', data.payload);
      break;
    case 'formalingo.fieldAnswered':
      console.log('Field completed:', data.payload.completedFields + '/' + data.payload.totalFields);
      break;
    case 'formalingo.documentHeight':
      document.querySelector('iframe').style.height = data.payload.height + 'px';
      break;
  }
});

Domain Whitelisting

By default, document signing pages can be embedded from any domain. To restrict embedding to specific domains, update the document settings:

curl -X PUT https://app.formalingo.com/api/v1/documents/DOC_ID \
  -H "Authorization: Bearer af_live_YOUR_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "settings": {
      "embed_allowed_domains": ["example.com", "*.company.io"]
    }
  }'

Set embed_allowed_domains to null to re-allow embedding from any domain (the default).

Troubleshooting

IssueCauseFix
Document doesn't load in iframeDomain blocked by whitelistCheck the document's embed_allowed_domains in settings
No auto-resizeSDK script not loadedVerify the embed.js script tag loads correctly
Console error: Refused to display in a frameCSP frame-ancestors restrictionAdd your domain to the document's allowed embed domains
Signing events not firingUsing old SDK versionEnsure you're loading the latest embed.js

On this page