Skip to main content
The OpnForm JavaScript SDK enables you to programmatically control embedded forms, listen to events, and build dynamic integrations. It includes automatic iframe resizing and full backward compatibility with existing embeds.

Installation

Include the SDK script after your form iframe:
The SDK automatically discovers OpnForm iframes on your page and initializes them. No additional setup required.

Automatic campaign attribution

The SDK automatically captures supported campaign parameters from the parent page and stores them with the submission under meta.attribution. Parameters already present in the iframe src take precedence over values from the parent page. Supported campaign parameters are utm_source, utm_medium, utm_campaign, utm_id, utm_term, utm_content, utm_source_platform, utm_creative_format, utm_marketing_tactic, gclid, gbraid, wbraid, dclid, fbclid, ttclid, and msclkid. Only these parameters are transmitted to the form. Other URL parameters and the complete parent URL are not captured. A raw cross-origin iframe without the SDK can only capture parameters included directly in its own src.

Quick Start


Events

Listen to form events to trigger custom actions, send data to analytics, or integrate with your application.

Available Events

Listening to Events

Removing Event Listeners


Form Methods

Access form instances using opnform.get('form-slug') and call methods to control the form.

Field Operations

Set the value of a specific field.
Set multiple field values at once.
Get the current value of a field.
Get all current form data.
Clear field values.

Error Handling

Theme Control

Form Actions

For forms embedded as popups:

Global SDK Methods

Form Management

Initialization Options

Programmatic Form Creation


Integration Examples

Google Analytics 4

Send to Custom API

Error Tracking

Dynamic Field Population


Custom Code Integration

The SDK is automatically available when using the Custom Code feature in OpnForm. You can add custom JavaScript directly in your form or workspace settings, and the window.opnform SDK will be ready to use.
Custom Code works without iframes - the SDK is initialized directly on your form page, giving you full access to form methods and events.

Adding Custom Code

  1. Go to your form’s SettingsCustom Code (or Workspace Settings for workspace-wide code)
  2. Add your JavaScript code in a <script> tag
  3. The SDK (window.opnform) is automatically available

Example: Google Analytics Tracking

Example: Facebook Pixel

Example: Conditional Logic with External Data

Example: Custom Validation Feedback

Example: Live Data Change Tracking

Accessing Form Data Directly


Backward Compatibility

Existing embeds using initEmbed() continue to work without changes. The SDK provides full backward compatibility.
We recommend upgrading to the new SDK to access event callbacks and programmatic control features.

Troubleshooting

Ensure the iframe has loaded and the id attribute matches the form slug:
Use opnform.getAll() to see discovered forms.
Make sure the SDK script is loaded after the iframe:
Commands require the form to be ready. Use the ready event:
The SDK includes iFrame Resizer. If resize isn’t working, ensure:
  • No CSS max-height restricting the iframe
  • The form is not in focused presentation style (which has fixed height)