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.
<form method="post" action="https://staging.unicorn-forms.com/api/forms/submit" responseType="json">
<input type="hidden" name="$to" value="{{ YOUR FORM KEY }}" />
<input type="text" name="website_url" value="" tabindex="-1" autocomplete="off" style="position:absolute;left:-9999px" aria-hidden="true" />
<input type="email" name="email" required placeholder="Your email">
<button type="submit">Send</button>
</form>
<script src="https://staging.unicorn-forms.com/js/magic-horn.js" defer></script>
On success
With responseType="json", the server returns JSON. Options:
- Stay on page: Default. Show a success message via
.uf-form-responseor useunicornToolz.onSuccess(). - Redirect: Add
<input type="hidden" name="$redirect" value="https://yoursite.com/thanks"/>
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 in the dashboard, you must include the reCAPTCHA v2 widget. The magic-horn script does not auto-inject it—add 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.
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.unicornToolzInit | Optional. If defined, called when the library initializes. Use to register callbacks before forms are found: window.unicornToolzInit = function(t) { t.onSuccess(...); } |
HTML only
Simplest option. Plain form, no JavaScript. Works everywhere.
<form method="post" action="https://staging.unicorn-forms.com/api/forms/submit">
<input type="hidden" name="$to" value="{{ YOUR FORM KEY }}" />
<input type="text" name="website_url" value="" tabindex="-1" autocomplete="off" style="position:absolute;left:-9999px" aria-hidden="true" />
<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="$redirect" 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://staging.unicorn-forms.com/api/forms/submit">
<input type="hidden" name="$to" value="FORM_KEY_1" />
<!-- contact form fields -->
</form>
<form method="post" action="https://staging.unicorn-forms.com/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_SECRETin 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.comor your configuredMAILER_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.