FormDexSecure form operations
Try FormDex
FormDexSecure form operations

A product by MeshDex

FormDex is a secure form operations platform for collecting, validating, and routing website submissions. Manage protected endpoints, email notifications, webhook delivery, and submission history from one reliable workspace.

Product

PlatformPricingDocumentation

Access

LoginRegisterReset password

Legal

Privacy PolicyTerms of ServiceRefund PolicyContact Us
  1. Home
  2. Documentation
  3. Integration
  4. Connect with browser JavaScript
Docs home

Integration guide

Connect with browser JavaScript

Send JSON or FormData with fetch, preserve accessible UI states, and handle FormDex failures without losing the visitor’s input.

Step by step

1

Choose the body format

Use JSON for text-only payloads. Use FormData for native forms, honeypot fields, captcha widgets, or file attachments.

2

Send credentials

Set X-API-Key for JSON requests. A native FormData request may include _api_key instead; do not set Content-Type manually for FormData because the browser must add its boundary.

3

Handle all responses

Check response.ok, parse the JSON body, show a useful inline error, and preserve the entered values when the request fails.

4

Prevent duplicate submits

Disable the submit button while pending and restore it in finally. Only clear the form after a successful response.

5

Protect public traffic

Keep allowed origins strict, use the honeypot in the actual form, and enable captcha for higher-risk public endpoints.

Honeypot in this integration

Where it belongs and who validates it

Required when JavaScript submits a public browser form. Put the visually hidden text input inside the same form before creating FormData. FormData will include the empty field automatically; never set or remove it in legitimate client code.

Read the honeypot fundamentals →

Working example

Complete form and fetch example

<form id="contact-form">
  <!-- HONEYPOT: exact FormDex field name; real visitors never fill it. -->
  <div aria-hidden="true" style="position:absolute;left:-10000px;width:1px;height:1px;overflow:hidden;">
  <label>Leave this field empty
    <input type="text" name="company" tabindex="-1" autocomplete="off" />
  </label>
</div>
  <label>Email <input type="email" name="email" required /></label>
  <label>Message <textarea name="message" required></textarea></label>
  <label>Attachments <input type="file" name="attachments" accept=".pdf,.jpg,.jpeg,.png" multiple /></label>
  <p id="form-error" role="alert"></p>
  <button type="submit">Send enquiry</button>
</form>

<script>
const form = document.querySelector("#contact-form");

form.addEventListener("submit", async (event) => {
  event.preventDefault();
  const button = form.querySelector("button[type=submit]");
  button.disabled = true;

  try {
    const response = await fetch("https://YOUR_FORMDEX_DOMAIN/api/forms/FORM_ID", {
      method: "POST",
      headers: { "X-API-Key": "YOUR_API_KEY" },
      body: new FormData(form)
    });
    const result = await response.json();
    if (!response.ok) throw new Error(result.message || result.error || "Submission failed");
    form.reset();
  } catch (error) {
    document.querySelector("#form-error").textContent = error.message;
  } finally {
    button.disabled = false;
  }
});
</script>

Troubleshooting

CORS error

Add the exact frontend origin and verify Test mode is not masking a production configuration problem.

415 Unsupported content type

Use JSON, URL-encoded data, or FormData.

Captcha verification failed

Obtain a fresh token for each attempt and use keys registered for the current hostname.

Repeated submissions

Disable the submit control while the request is pending.

Before you start

  • • A FormDex endpoint and API key
  • • An allowed browser origin
  • • A field schema matching the submitted JSON keys
  • • A fresh provider token for every submission when captcha is enabled

Production notes

  • • Never log API keys, captcha tokens, or full customer payloads in browser telemetry.
  • • FormData automatically includes the visually hidden honeypot input and captcha widget response.
  • • For JSON, set Content-Type: application/json and JSON.stringify the body.
View the complete integration overview →