Core Forms
WordPress forms with payments, digital products and spam protection.
Headless mode lets a site that doesn’t run WordPress show a Core Forms form and send its submissions back to WordPress. Use it for a static HTML site, an Astro or Next.js build, or a React, Vue or Svelte app. You build the form in Core Forms as usual, and every submission runs through the same validation, spam checks, storage and actions as a form on a WordPress page.
There are two ways to connect:
<div> and one <script> tag. The script loads the form’s HTML from WordPress, shows it, and posts submissions back.The Headless section has a full guide for each part:
Headless access needs the Headless API module, a site-wide API key and a per-form switch.

cf_), then save the settings.https://example.com or http://localhost:4321.You can set the API key in wp-config.php instead of step 3, for example to use the same key on staging and production: define( 'CORE_FORMS_HEADLESS_API_KEY', 'cf_...' );. The settings then show it as set in wp-config.php. See Keys in wp-config.php.
The Headless tab shows a status banner. It warns you when the API key isn’t set, or when the form is enabled but neither reCAPTCHA nor Turnstile is configured. Once both are in place it shows Ready to embed. Its snippets show your URLs and a masked key: Copy copies the real key and Reveal shows it.
Copy the snippet from the form’s Headless tab. It looks like this:
<div data-cf-form="contact" data-cf-key="YOUR_SITE_API_KEY"></div>
<script src="https://your-wordpress-site.com/wp-json/core-forms/v1/embed.js" defer></script>
data-cf-form takes the form’s slug or numeric ID.data-cf-key is the site API key.embed.js mounts every [data-cf-form] element on the page once the document is ready.When a visitor submits the form, the script posts the answers with the API key in the X-Core-Forms-Key header, as JSON or as multipart when the visitor chose a file. It also sends the page URL, so [CF_REFERRER_URL] and the other referrer variables point at the page the visitor was on, not at the WordPress REST endpoint.
After a successful submission the script replaces the form with the form’s success message, or follows the form’s redirect URL. If the submission fails, it shows the error message above the form.
The script fires these events on the host <div>. They bubble, so you can listen on a parent element too.
| Event | When it fires | event.detail |
|---|---|---|
cf:mounted |
The form HTML is in place | The form schema |
cf:submit |
The visitor submits | { form }, the <form> element |
cf:success |
The submission was accepted, before any redirect | The response body |
cf:error |
Loading or submitting failed | The error or response body |
document.querySelector('[data-cf-form]').addEventListener('cf:success', (event) => {
console.log('Submitted', event.detail);
});
Paste the snippet where the form should appear. Nothing else is needed.
Paste the snippet into a component or page. Add is:inline so Astro leaves the external script alone:
<div data-cf-form="contact" data-cf-key={import.meta.env.PUBLIC_CF_KEY}></div>
<script is:inline src="https://your-wordpress-site.com/wp-json/core-forms/v1/embed.js" defer></script>
In a single-page app the form’s element often appears after the page has loaded, so mount it yourself. Load embed.js once (for example in index.html), then call window.CoreFormsEmbed.mount() when the element is in the DOM. The script also exposes window.CoreFormsEmbed.init(), which mounts every element that hasn’t been mounted yet.
React:
import { useEffect, useRef } from 'react';
export function ContactForm() {
const ref = useRef(null);
useEffect(() => {
window.CoreFormsEmbed?.mount(ref.current);
}, []);
return <div ref={ref} data-cf-form="contact" data-cf-key={import.meta.env.VITE_CF_KEY} />;
}
Vue:
<script setup>
import { onMounted, ref } from 'vue';
const key = import.meta.env.VITE_CF_KEY;
const host = ref(null);
onMounted(() => window.CoreFormsEmbed?.mount(host.value));
</script>
<template>
<div ref="host" data-cf-form="contact" :data-cf-key="key"></div>
</template>
Svelte:
<script>
import { onMount } from 'svelte';
const key = import.meta.env.VITE_CF_KEY;
let host;
onMount(() => window.CoreFormsEmbed?.mount(host));
</script>
<div bind:this={host} data-cf-form="contact" data-cf-key={key}></div>
Don’t render children inside the host element. The script replaces its contents.
Use this route when you want to render the form with your own components.
GET /wp-json/core-forms/v1/forms/{id-or-slug}. This endpoint is public.POST /wp-json/core-forms/v1/forms/{id}/submit with the X-Core-Forms-Key header.The schema response contains:
id, slug and titlehtml: the complete rendered formfields: each field’s name, type, required, label and optionsmessages: the form’s messagessubmit_url: the submit endpointcaptcha: the captchas this form checks, with their public site keysrequires_captcha: true when a reCAPTCHA or Turnstile site key is savedconst res = await fetch('https://your-wordpress-site.com/wp-json/core-forms/v1/forms/42');
const form = await res.json();
await fetch(form.submit_url, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'X-Core-Forms-Key': 'YOUR_SITE_API_KEY',
},
body: JSON.stringify({
name: 'Ada',
email: 'ada@example.com',
_cf_h42: '', // honeypot: optional, must be empty if sent
_cf_page_url: window.location.href, // optional: fills [CF_REFERRER_URL]
}),
});
Every Core Forms form has a hidden honeypot field named _cf_h followed by the form ID, for example _cf_h42. The drop-in embed sends it for you because it’s part of the form HTML.
With your own markup you can leave it out: since 4.15.1 the endpoint adds an empty one for you, because the API key already identifies your app. If you do send it, keep it empty. A filled honeypot is treated as a bot, so the submission isn’t saved and runs no actions, while the endpoint still answers with a generic success message.
Before 4.15.1, a submission without the honeypot field was silently dropped in the same way. Update the plugin if your app sends only its own fields.
For checkboxes and other multi-value fields, send an array. Keys ending in [], such as "topics[]", are accepted too and are treated the same as "topics".
| Status | Meaning |
|---|---|
200 |
The submission was accepted. The body carries the processor’s message object, and redirect_url when the form redirects. |
422 |
Validation or processing failed. The body carries the error message. |
401 |
The X-Core-Forms-Key header is missing or wrong. |
403 |
The form isn’t enabled for headless use. |
404 |
No form matches the ID or slug. |
503 |
No API key is set on the site. |
The message is an object such as { "type": "success", "text": "Thanks!" }, not a plain string.
The submit endpoint feeds the request into the same processor as a form on a WordPress page. That means:
WordPress nonces don’t work across origins. The submit endpoint creates its own nonce on the server after checking the API key, so forms keep working when Enable Nonce is on.
The REST routes send CORS headers so browsers on other sites can call them. No cookies are sent or accepted.
* allows any origin.CORS is a browser rule. It doesn’t stop a server or script from calling the endpoint directly, so it doesn’t replace the API key or a captcha.
The key is for submitting to forms you’ve marked as headless, and it doesn’t sign in to WordPress. Treat it as a secret, because a leaked key can be abused.
To keep it out of the browser, post to a route on your own server and add the header there. The Headless tab has ready-to-copy proxy examples for Cloudflare Workers or Pages Functions, Next.js (App Router) and Astro server endpoints. Keep the key in a server-only environment variable, never in a PUBLIC_ or NEXT_PUBLIC_ one.
With a proxy, WordPress records the IP address of your server unless the proxy passes the visitor’s IP with a proxy secret.
Rotate the key any time from Settings > Headless / REST > Generate. Every existing client stops working as soon as you save the new key.
Configure reCAPTCHA or Turnstile under Core Forms > Settings before you publish a headless form. Once reCAPTCHA keys are saved, every submission must carry a valid token in g-recaptcha-response. Turnstile is checked on forms where it’s turned on, and expects its token in cf-turnstile-response. A missing or invalid token rejects the submission.
The schema’s requires_captcha flag is true whenever a reCAPTCHA or Turnstile site key is saved, even if Turnstile is off for this particular form.
The drop-in embed loads the captcha script and sends the token. With your own markup, use the captcha script. Test a real submission before going live.
| Method | Route | Auth |
|---|---|---|
GET |
/wp-json/core-forms/v1/forms/{id-or-slug} |
Public |
POST |
/wp-json/core-forms/v1/forms/{id-or-slug}/submit |
X-Core-Forms-Key header |
GET |
/wp-json/core-forms/v1/embed.js |
Public |
The key is accepted only in the header, never as a query parameter.
Still stuck? Open a support ticket