import staticFormsPlugin from "@cloudflare/pages-plugin-static-forms";
export const onRequest: PagesFunction = staticFormsPlugin({
respondWith: async ({ formData, name }) => {
const email = formData.get('email');
// Serialize the formData if you have multiple fields or need to store it as a JSON object
const dataToStore = JSON.stringify({ email: email });
// Create a unique identifier for this submission
const submissionId = new Date().toISOString();
// Save the serialized data to your KV namespace
await formSubmissions.put(`submission-${submissionId}`, dataToStore);
// Return a response to the user
return new Response(`Hello, ${email}! Thank you for submitting the ${name} form. Your submission has been saved.`);
}
});
import staticFormsPlugin from "@cloudflare/pages-plugin-static-forms";
export const onRequest: PagesFunction = staticFormsPlugin({
respondWith: async ({ formData, name }) => {
const email = formData.get('email');
// Serialize the formData if you have multiple fields or need to store it as a JSON object
const dataToStore = JSON.stringify({ email: email });
// Create a unique identifier for this submission
const submissionId = new Date().toISOString();
// Save the serialized data to your KV namespace
await formSubmissions.put(`submission-${submissionId}`, dataToStore);
// Return a response to the user
return new Response(`Hello, ${email}! Thank you for submitting the ${name} form. Your submission has been saved.`);
}
});