Skip to Content
Receive Submissions

Drop-in script

Add one script tag to turn marked forms into forms that solve proof of work, render Turnstile and upload large Files before they submit.

The drop-in script upgrades the forms you mark on a page. A marked form submits in the background, shows errors in the page and then sends the Visitor to the Form's Redirect URL or thank-you page. The script is served from the same hostname as the endpoint and adds no dependencies to your site.

Use it when the Site has "Require proof of work" on, uses Turnstile, or accepts Files larger than about 4 MB. A plain HTML form cannot do those. See HTML forms.

Add the script

  1. Add the script tag to the page, once:

    <script src="https://us.insaneforms.com/v1.js" defer></script>

    The Form's Settings show it under "Script tag".

  2. Add the data-insane-forms attribute to each form that should use it. The form's action is the Form's endpoint:

    <form
      action="https://us.insaneforms.com/f/<form-id>"
      method="POST"
      data-insane-forms
    >
      <input name="email" type="email">
      <button>Send</button>
      <p data-insane-forms-error></p>
    </form>

Keep the defer attribute. The script reads the forms on the page once, when it runs, so forms added to the page afterwards are not upgraded.

The script checks the clicked submit button's formaction when set, otherwise the form's action. It handles the Submission only if that URL has the same origin as the script and a path of /f/<form-id>, with an optional trailing slash. Other actions submit as normal HTML forms. Without JavaScript, a marked form still posts to the endpoint as a plain form.

What the script does

  • When the Visitor first focuses the form, the script checks the form's own action. If it matches the script's origin and path rule, the script asks for a challenge and starts solving proof of work in the background.
  • If the Site has Turnstile keys, it loads the Turnstile widget into the form. Put an element with data-insane-forms-turnstile where the widget should appear. If there is none, the widget is added at the end of the form.
  • On submit, it uploads each File straight to storage, then posts the fields with Accept application/json. See File uploads.
  • On success, it sends the browser to the redirect address in the answer.
  • On failure, it shows the message.

The script sends the form only once at a time. A second select while one send is in progress does nothing.

Show errors

Put an element with the data-insane-forms-error attribute inside the form. The script writes the error message into it. Without one, the script shows the message in a browser alert.

Messages you may see include "Complete the verification before sending the form." when the Turnstile widget has not produced a token, and the endpoint's own messages, for example "Submission too large" or "Too many submissions. Try again in a few minutes."

Reset after sending

After each send the script resets the Turnstile widget, so a Visitor who sends the form again must complete it again.

When to use the packages instead

The script is built from @insane-forms/core. To send forms from your own code or a framework, use the packages: Core and React.

On this page