Open the form from your own code

Open, close and place your form with JavaScript.

Open your form from any button in your app, put the form in any element on your page, and run your own code after each submission.

Add the script

Add the script once on every page that shows a form.

<script src="https://wlforms.com/embed.js" async></script>

Nothing loads until a form is shown.

Open and close a popup

WeLoveForms.open("frm_yourform");
WeLoveForms.close();

Optional: open the form in the corner of the page instead.

WeLoveForms.open("frm_yourform", { mode: "slide-in" });

One popup is open at a time. Opening another closes the first.

Put the form in your page

WeLoveForms.mount("#feedback", "frm_yourform");

The form grows to fit every question. Calling mount again on the same element does nothing.

Run code after each submission

WeLoveForms.open("frm_yourform", {
  onSubmit: ({ formId, submissionId }) => showThanks(),
  onClose: () => {},
});

onClose runs when the popup is closed with ×, Esc or a click outside.

For forms added with HTML, listen for the wlf:submitted event:

window.addEventListener("wlf:submitted", (e) => console.log(e.detail.submissionId));

Your page never gets the answers. Read them in your inbox or send them to a webhook.

Open the form before the script loads

The script loads in the background. To open the form right away, queue the call.

window.WeLoveForms = window.WeLoveForms || { q: [] };
WeLoveForms.q.push(["open", "frm_yourform"]);

Queued calls run as soon as the script loads, or straight away if the script is already there.

Show forms you add later

Added data-wlf-form or data-wlf-open elements after the page loaded? Call WeLoveForms.scan().

Options

Option Use for
mode "popup" or "slide-in", for open. Popup is the default.
hiddenFields Values for your hidden fields, like { user_id: "42" }
prefill Answers filled in for people, by column name, like { email: "[email protected]" }. People can still change them.
onOpen When the popup opens
onClose When the popup closes
onSubmit When the answer is saved, with formId and submissionId
esc