How to open OFORM for filling from website
To make an online form in the OFORM format available for filling in and downloading as PDF from your website, follow the steps below:
- Find and open the index.html file of your ONLYOFFICE Docs.
-
Connect it to the Document Server API by specifying the path to the API JavaScript file:
<script type="text/javascript" src="https://documentserver/web-apps/apps/api/documents/api.js"></script>
-
Add the button element to open the form:
<button onclick="open_form()">Open Form</button>
-
Add the div element where the editor will be opened:
<div id="placeholder"></div>
-
Add the script to close the editor in case it is open:
if (this.docEditor) { this.docEditor.destroyEditor() }
-
Create the full URL address to the form template you need to open:
const url = "https://example.com/url-to-example-document.oform";
-
Create the key to identify the file
const key = filename + ".oform";
Please note that the key field is not passed to the configuration of the editors. This field will be automatically generated as a random number. This allows making all sessions of opening the form independent. So, collaboration on the OFORM file is disabled. That's why anyone can open the form and fill it out without disturbing others. -
Add the script initializing the Document Editor with the configuration for the document you want to open and open the editor in the placeholder element:
this.docEditor = new DocsAPI.DocEditor("placeholder", { "document": { "fileType": "oform", "title": "Form", "url": url }, "documentType": "word" });
The full code fragment looks like this:
<script type="text/javascript" src="https://documentserver/web-apps/apps/api/documents/api.js"></script> <button onclick="open_form()">Open Form</button> <div id="placeholder"></div> <script> function open_form() { if (this.docEditor) { this.docEditor.destroyEditor() } const url = "https://example.com/url-to-example-document.oform"; const key = filename + ".oform"; this.docEditor = new DocsAPI.DocEditor("placeholder", { "document": { "fileType": "oform", "title": "Form", "url": url }, "documentType": "word" }); } </script>
Once done, a form can be opened for filling. After filling in the fields (the required ones are highlighted with the red border), you can get a PDF file. To do so, click the Download button.
