Use this file to discover all available pages before exploring further.
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.
// Listen to form submissionopnform.on("submit", function (data) { console.log("Form submitted!", data); console.log("Submission data:", data.data);});// Set a field valueopnform.get("my-form").setField("email", "user@example.com");// Toggle dark modeopnform.get("my-form").toggleDarkMode();
// Remove specific handlerconst handler = (data) => console.log(data);opnform.on("submit", handler);opnform.off("submit", handler);// Remove all listeners for an eventopnform.off("submit");
opnform.get("my-form").setField("email", "user@example.com");opnform.get("my-form").setField("name", "John Doe");// Works for hidden fields tooopnform.get("my-form").setField("utm_source", "google");
// Check if a field has an errorconst hasError = opnform.get("my-form").hasError("email");// Get error message for a fieldconst errorMsg = opnform.get("my-form").getError("email");// Get all errorsconst errors = opnform.get("my-form").getErrors();// { email: "Invalid email format", phone: "Required" }
// Toggle dark modeopnform.get("my-form").toggleDarkMode();// Set specific modeopnform.get("my-form").setDarkMode(true); // Darkopnform.get("my-form").setDarkMode(false); // Lightopnform.get("my-form").setDarkMode("auto"); // Follow system// Check current modeconst isDark = opnform.get("my-form").isDarkMode();
// Submit form programmaticallyopnform.get("my-form").submit();// Reset form to initial stateopnform.get("my-form").reset();// Focus on first error fieldopnform.get("my-form").focusFirstError();
// Open popupopnform.get("my-form").open();// Close popupopnform.get("my-form").close();// Toggle popupopnform.get("my-form").toggle();// Check if openconst isOpen = opnform.get("my-form").isOpen();
// Get a specific form instanceconst form = opnform.get("my-form-slug");// Get all forms on the pageconst forms = opnform.getAll();// Check if a form is readyconst isReady = opnform.isReady("my-form-slug");
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.
<script> opnform.on("error", function (data) { // Show custom toast notification for errors Object.values(data.errors).forEach(function (error) { showToast(error, "error"); }); }); opnform.on("submit", function (data) { showToast("Thank you for your submission!", "success"); });</script>
<script> opnform.on("dataChange", function (data) { console.log("Field changed:", data.changedField); console.log("New value:", data.newValue); // Example: Show/hide elements based on form data if (data.changedField === "country" && data.newValue === "US") { document.querySelector(".us-only-info").style.display = "block"; } });</script>
<script> opnform.once("ready", function () { var form = opnform.get("my-form-slug"); // Get all current form data var data = form.getData(); console.log("Current form data:", data); // Get specific field value var email = form.getField("email"); // Check if field has validation error if (form.hasError("email")) { console.log("Email error:", form.getError("email")); } // Get current page (for multi-page forms) var page = form.getCurrentPage(); console.log("Page " + (page.index + 1) + " of " + page.total); });</script>
Existing embeds using initEmbed() continue to work without changes. The
SDK provides full backward compatibility.
<!-- Old embed code still works --><iframe id="my-form" src="https://opnform.com/forms/my-form"></iframe><script src="https://opnform.com/widgets/iframe.min.js"></script><script> initEmbed("my-form", { autoResize: true });</script>
We recommend upgrading to the new SDK to access event callbacks and
programmatic control features.