HTML FormsSubmitting
JavaScript & fetch
Post JSON to the endpoint from fetch, Axios or any HTTP client and handle the response yourself.
If you want full control of the UI, skip the script and call the endpoint yourself. Send JSON with an Accept: application/json header and you get JSON back.
contact.js
const form = document.querySelector('#contact');
form.addEventListener('submit', async (e) => {
e.preventDefault();
const data = Object.fromEntries(new FormData(form));
const res = await fetch('https://api.formclick.io/submit', {
method: 'POST',
headers: { 'Content-Type': 'application/json', Accept: 'application/json' },
body: JSON.stringify({ access_key: 'YOUR_ACCESS_KEY', ...data }),
});
const result = await res.json();
if (result.success) {
form.reset();
alert(result.message);
} else {
alert(result.message || 'Something went wrong');
}
});Response
{
"success": true,
"message": "Thank you! Your message has been received.",
"redirect_url": "https://yourwebsite.com/thanks" // only when a redirect applies
}Errors use the same shape with success: false and a readable message. Always check success rather than only the HTTP status. The full list is in Errors.
CORS is open (
Access-Control-Allow-Origin: *), so you can call the endpoint from any website or local development server.Still need help? Contact support or email support@formclick.io.