Skip to content

Manipulate from answers before submitting to Server via JS/Axios/Ajax #4485

Answered by eliasu
eliasu asked this question in Q&A
Discussion options

You must be logged in to vote

Ok if anybody wonders. I played around, and found a solution. i don't know if thats best practice, but it works. Please feel free to comment and improve.

Here are the Docs to submit forms via JS (which we need, because we want to manipulate the data before submitting). But here are the steps for it in short:

1. Add Dependency

const axios = require('axios').default;

2. Get form and create defaults for axios

let form = document.getElementById("your-form-id");
axios.defaults.headers.common['X-Requested-With'] = 'XMLHttpRequest';

3. Add submit eventHandler

form.addEventListener("submit", function (e) {
	// prevent default post method by statamic
	e.preventDefault();
		
	// create new form dat…

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by eliasu
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
1 participant