Skip to content

Headless submissions via custom REST API / PHP? #2034

Answered by engram-design
mandrasch asked this question in Q&A
Discussion options

You must be logged in to vote

The best method is to use GraphQL mutations for headless, but using REST is also possible. Your best bet is to mimic a POST submission just like a traditional form would. We don't have docs about this, purely because it's very straightforward to create a Twig template, render your form, test submission and inspect the payload sent to the server. So long as you copy that, you're fine.

For example:

// Method 1: construct an object of data
var body = {
"action": "formie/submissions/submit",
"handle": "contactForm",
"siteId": "1",
"fields[yourName]": "dave",
"fields[emailAddress]": "[email protected]",
"fields[message]": "this is a message",
};

// Append CSRF token
window.csrfTokenName = "{{ cr…

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@mandrasch
Comment options

Answer selected by mandrasch
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants