Skip to main content

Developer tools

Headless / Astro / Next in Core Forms

Render and submit Core Forms from Astro, Next.js, or any non-WordPress site.

Bundled with Core Forms, the WordPress forms plugin with every premium feature in the box. No add-on tax.

Bundled, no add-on tax Unlimited sites Use code BLACKFRIDAY for 40% off either plan. Ends December 2 (IST).

Headless WordPress forms let a site that doesn't run WordPress show a Core Forms form and send each submission back to WordPress. You need the Headless API module, a site API key and the form's Headless switch, plus reCAPTCHA or Turnstile before launch. Standard fields work over JSON. Payments and file uploads need a page hosted on WordPress.

Any form can be shared over REST, so a site that doesn't run WordPress can show it and post answers as JSON. WordPress runs validation, spam checks, storage and actions. Payments and file uploads don't work through the JSON endpoint, so keep those forms on a page hosted by WordPress.

Turn on the Headless API module (it's off by default), save one API key for the site, then switch on each form. Use the drop-in embed, which puts the key in the page, or fetch the form and submit through your own server route to keep the key private.

Headless / Astro / Next at a glance

Works with
Static HTML, Astro, Next.js, React, Vue, Svelte
Connect via
Drop-in embed.js or native fetch
Auth
Site API key in the X-Core-Forms-Key header
Turn on in
Modules > Headless API, then Settings > Headless / REST, then the form's Headless tab
Not over JSON
Payments and file uploads
Spam checks
reCAPTCHA or Turnstile, honeypot, blocklist, Akismet
Endpoints
/wp-json/core-forms/v1/forms/{id-or-slug}

Full reference: Headless forms docs

What you get

How Headless / Astro / Next works in Core Forms

GET form schema

A public endpoint returns the rendered HTML and a structured field list for your own components.

POST submit endpoint

Accepts text answers as JSON, then runs validation, spam checks, storage and actions. It doesn't take files or payments.

embed.js widget

Add a <div data-cf-form="…"> and <script src=".../embed.js">. It suits single-page forms with standard fields.

CORS settings

List your front ends in Allowed origins, but don't use the list as access control or spam protection. Any website, script or server can reach the endpoints.

Use cases

What people build with Headless / Astro / Next and Core Forms

Contact form on Astro

Paste the div and script snippet into a page, add is:inline so Astro leaves the script alone, and entries land in the form's Submissions tab.

Your own components in Next.js

Fetch the public form schema, render inputs from its fields list, and post JSON through a server route that adds the key and sets the form ID.

Forms in React or Vue apps

Load embed.js once, call window.CoreFormsEmbed.mount() when the host element exists, and listen for cf:success to update your UI.

One backend for several sites

List every front end in Allowed origins and keep emails, webhooks and CRM actions configured once in WordPress.

Set it up

Connect Headless / Astro / Next in 3 minutes

  1. 1

    Turn on the Headless API module

    Core Forms > Modules > turn on Headless API. It's off by default, and the headless routes return 404 until it's on.

  2. 2

    Create the API key

    Core Forms > Settings > Headless / REST > Generate. Add your front ends to Allowed origins, then save.

  3. 3

    Enable the form

    Edit the form, open its Headless tab, turn on Headless mode and save. Note the form ID and slug.

  4. 4

    Set up a captcha

    Configure Turnstile or reCAPTCHA v3, then load the captcha script on the external site, which can't use the WordPress scripts.

  5. 5

    Connect your site

    Paste the embed, or install a server-route starter to keep the key private. Send a test entry and check Submissions.

Every setting, filter, and error message is documented in the Headless forms docs.

Drop-in vanilla JS embed

<div data-cf-form="contact" data-cf-key="YOUR_SITE_API_KEY"></div>
<script src="https://cms.example.com/wp-json/core-forms/v1/embed.js" defer></script>
Sample code

Download a starter for your stack

Each server starter needs the submit script and server settings. Astro, Next.js and Cloudflare also need the shared proxy. Save each file where its card says, replace the example values, and send a test entry before launch.

Inside Core Forms

See it in WP-Admin

Core Forms global settings — Headless / REST section with the API key field, Generate / Show / Copy controls, and the Allowed origins textarea
One API key for the site and the Allowed origins list, under Core Forms > Settings > Headless / REST. The list isn't access control.
Headless tab of a demo form with Headless mode on, embed and native fetch snippets using a placeholder API key, and collapsed cURL and reference cards
The per-form switch and its snippets, shown on a demo site. On your site they contain your real key, so hide it before you share a screenshot.
Drop-in embed card with a data-cf-form element, a placeholder data-cf-key and the embed.js script tag
The drop-in embed for standard single-page forms. This route makes the API key public.
Native fetch card that requests a core-forms/v1 form and posts JSON with a placeholder X-Core-Forms-Key header and _cf_page_url
Native fetch with your own markup. Run the keyed request on your server to keep the key private. The _cf_page_url field fills [CF_REFERRER_URL].
Good to know

Requirements and limits

  • Set up reCAPTCHA or Turnstile before you publish a headless form, because the Headless tab only shows Ready to embed once both the key and a captcha are in place.
  • The drop-in embed inserts form HTML with innerHTML, so scripts inside it don't run: load the captcha provider's script on your own site and test a real submission.
  • JSON carries no files. Link to a standalone form page on WordPress for uploads, and keep payment forms there too.
  • The embed doesn't load the WordPress scripts for steps, conditions or live calculations.
  • Behind a proxy, WordPress records your server's IP and ignores X-Forwarded-For. Set the form's rate limit to 0, rate limit the proxy and turn off Prevent duplicates.
  • List your front ends in Allowed origins, but don't use it as access control. Treat the form schema and submit responses as readable by any website, script or server.
  • If you write your own proxy, set id to your form ID on the server and accept only plain values and lists.
  • Rotating the API key stops every existing client as soon as you save the new one.
Documentation

Headless / Astro / Next docs and references

The Core Forms docs live on gauravtiwari.org/docs, with every setting, filter, and troubleshooting step for this integration.

FAQ

Headless / Astro / Next integration questions

Does the front-end site need to run WordPress?
No. The form is built and stored in Core Forms on your WordPress site, and the external site only renders it and posts answers back. Static HTML, Astro, Next.js, React, Vue and Svelte all work, as long as your WordPress REST API is reachable.
Is it safe to put the API key in the browser?
Treat it as a secret. It doesn't sign in to WordPress, but anyone who copies it can abuse it, so a server route that adds the header is the safer choice. If it must be in the browser, keep a captcha on and rotate the key when you see abuse. See the security guide.
Do my emails, webhooks and integrations still run?
Yes, for accepted submissions. The endpoint checks required fields, conditional required rules and spam, then runs storage and the form's actions. With draft publishing on, it uses the published form, not the draft.
Do payments and file uploads work headless?
No. The JSON endpoint carries no files and can't complete a payment. Link to a standalone form page on WordPress for either. The fields and features guide lists what each route supports.
Do I have to send the honeypot field with my own markup?
No. Current versions add an empty honeypot for you because the API key already identifies your app. If you do send _cf_h plus the form ID, keep it empty: a filled honeypot is treated as a bot, nothing is saved, and the endpoint still returns a generic success message.
What status codes does the submit endpoint return?
200 means accepted, 400 means the JSON is malformed, 401 means the X-Core-Forms-Key header is missing or wrong, 403 means the form isn't enabled for headless use, 404 means no form matched or the Headless API module is off, 422 means validation, a spam check or a limit failed, 500 means the processor returned no response, and 503 means no API key is set on the site. See the API reference.
How do I send checkbox answers?
Send an array for checkboxes and other multi-value fields. Keys ending in [], such as topics[], are accepted and treated the same as topics.

Bundled with every Core Forms license.

Headless / Astro / Next and every Core Forms-built integration on this site are included with your license. Use code BLACKFRIDAY for 40% off either plan. Ends December 2 (IST).

Black Friday Sale

40% off Core Forms

Forms, polls, surveys, payments, and licensing — every feature, unlimited sites, one plugin.

Copy your code

Those are the after-discount prices. Paste BLACKFRIDAY at checkout to apply it. BLACKFRIDAY40 works too.

Ends December 2 (IST)