Docs navigation

Embed forms in minutes

Add contact forms, lead captures, and feedback widgets to any site. One snippet. No backend. Works with static sites, React, WordPress—anything.

AJAX implementation

Best for modern sites. Submits without page reload, includes reCAPTCHA, and handles errors inline.

Code snippet
<form method="post" action="https://amorphous.to/api/forms/submit" data-unicorn-form="discover">
    <input type="hidden" name="$to" value="{{ YOUR FORM KEY }}" />
    <input type="email" name="email" required placeholder="Your email">
    <button type="submit">Send</button>
</form>
<script src="https://amorphous.to/js/magic-horn.js" defer></script>

Handling success messages

With responseType="json" (or data-unicorn-form="discover"), the server returns JSON. Here are all the ways you can show a success message:

Method How it works
.uf-form-response div Add a hidden div with class uf-form-response (e.g. style="display:none;"). Magic-horn will show it on success. Put your thank-you message inside.
$success redirect Add <input type="hidden" name="$success" value="https://yoursite.com/thanks"/>. User is redirected to that URL on success.
unicornToolz.onSuccess() Register a callback: unicornToolz.onSuccess(function(data, form) { ... }). Run your own logic—show a toast, update UI, clear the form, etc.
uf:submit-success event If using the embed SDK, listen for form.addEventListener('uf:submit-success', (e) => { ... }). The event detail contains the response data.
Automatic fallback If none of the above are set up, magic-horn will show a generic "Thank you for your submission" and clear the form.

The automatic fallback only runs when no other success mechanism exists. To suppress it, register any of the above—for example, unicornToolz.onSuccess(function(){}) with an empty callback.

JavaScript success example

Register a callback with unicornToolz.onSuccess(). It receives the server response and the form element.

// Run before or after magic-horn.js loads
unicornToolz.onSuccess(function(response, form) {
  console.log('Submitted!', response);
  // response.status, response.message, response.actions, etc.
  form.reset(); // optional: clear the form
});

reCAPTCHA (when spam prevention is enabled)

If your form has spam prevention enabled, include the reCAPTCHA v2 widget. The script may inject it if missing. To add manually, place this inside your form before the submit button:

<!-- reCAPTCHA v2 - required when spam prevention is enabled -->
<div class="form-group">
  <div class="g-recaptcha" data-size="normal" data-sitekey="YOUR_SITE_KEY"></div>
</div>

Replace YOUR_SITE_KEY with your reCAPTCHA site key from the dashboard. The embed code in the form editor includes this automatically when spam prevention is on.

Honeypot (when enabled)

Enable Add Honeypot in form settings. An invisible field is injected automatically—no code needed.

Built-in callbacks

Callback Description
unicornToolz.onSuccess(fn)Called when a form submits successfully. fn(response, form) — response has status, message, actions.
unicornToolz.onErrors(fn)Called when submission fails. fn(errorData, form, response) — errorData has errors, code.
window.unicornToolzInitOptional. If defined, called when the library initializes. Use to register callbacks before forms are found: window.unicornToolzInit = function(t) { t.onSuccess(...); }

The script

Load the script to enable AJAX submission, error handling, and automatic enhancements. It discovers forms by attribute:

<form data-unicorn-form="discover" ...>

Forms with data-unicorn-form="discover" are intercepted by the script. Submissions go via AJAX; errors are shown inline. The script can also inject missing fields when needed—check form settings in the dashboard.

Spam prevention

Submissions use multiple layers of protection. Enable options in form settings.

  • Background checks — Every submission is evaluated. Suspicious patterns are flagged or blocked.
  • reCAPTCHA — Enable "Spam Prevention" in form settings. Add the Google widget to your form; the embed code includes it when enabled. The script may auto-inject it if missing.
  • Honeypot — Enable "Add Honeypot" in form settings. An invisible field is injected automatically. No code needed.

Blocked submissions are not emailed or stored as valid. Check the dashboard for spam metrics.

Domain lock

Restrict submissions to specific domains. Add allowed domains in form settings under "Secure Form By Domains" (e.g. yoursite.com). Submissions from other origins are rejected.

Paste domains with or without protocol—they are normalized automatically.

HTML only

Simplest option. Plain form, no JavaScript. Works everywhere.

Form code
<form method="post" action="https://amorphous.to/api/forms/submit">
    <input type="hidden" name="$to" value="{{ YOUR FORM KEY }}" />
    <input type="email" name="email" required placeholder="Your email">
    <button type="submit">Send</button>
</form>

Behavior

  • On success (default): User is redirected to a thank-you page.
  • On success (custom): Add <input type="hidden" name="$success" value="YOUR_URL"/> to redirect to your URL.
  • On error: User stays on the page; errors are shown.

Multiple forms on one page

Each form needs its own $to (form key). Use a different form key per form, or the same key if they should go to the same inbox.

<form method="post" action="https://amorphous.to/api/forms/submit">
  <input type="hidden" name="$to" value="FORM_KEY_1" />
  <!-- contact form fields -->
</form>
<form method="post" action="https://amorphous.to/api/forms/submit">
  <input type="hidden" name="$to" value="FORM_KEY_2" />
  <!-- newsletter signup fields -->
</form>

Legacy forms with reCAPTCHA

If you have older forms using a hardcoded reCAPTCHA site key (e.g. 6LfF5_...), they will continue to work as long as:

  • The RECAPTCHA_SECRET in your environment matches the secret for that site key (same Google reCAPTCHA admin project).
  • The form action URL points to the correct mailer endpoint (mailer.unicorn-forms.com or your configured MAILER_ENDPOINT).

To migrate legacy forms to the new site key: copy the embed code from the form editor (it includes the correct g-recaptcha div and site key), then replace the old form markup on your site. The magic-horn script and validation flow remain the same.

Lead capture

Include an email field to capture leads. The dashboard shows email in submissions. Add any fields you need—name, message, phone, etc.

Hidden fields reference

Field Description
$toYour form key (required)
$successURL to redirect to on success (alias: $redirect)
$responseTypeSet to json for AJAX (no page reload)
Form example

Ready to collect leads?

Create a free account and get your form key in seconds.

Get started free