From 1cc7d9cca4b3ad099d928e0cc83cbc27eb3bfc57 Mon Sep 17 00:00:00 2001 From: Dan Head Date: Tue, 2 Feb 2021 22:18:00 +0000 Subject: [PATCH] feat(contact): use formdata to construct post --- src/pages/contact.js | 23 +++-------------------- 1 file changed, 3 insertions(+), 20 deletions(-) diff --git a/src/pages/contact.js b/src/pages/contact.js index 863ddb2..4e65af8 100644 --- a/src/pages/contact.js +++ b/src/pages/contact.js @@ -22,31 +22,14 @@ import Envelope from "../icons/envelope.svg"; import Phone from "../icons/phone.svg"; import Team from "../icons/team.svg"; -const encodeData = data => - Object.keys(data) - .map(key => `${encodeURIComponent(key)}=${encodeURIComponent(data[key])}`) - .join("&"); - export default function Index({ data }) { const [submitted, setSubmitted] = useState(); - const handleSubmit = e => { e.preventDefault(); - const body = encodeData({ - "form-name": "contact", - name: e.target.name.value, - email: e.target.email.value, - telephone: e.target.telephone.value, - start: e.target.start.value, - stage: e.target.stage.value, - status: e.target.status.value, - message: e.target.message.value, - file: e.target.file.value - }); fetch("/contact", { method: "POST", headers: { "Content-Type": "application/x-www-form-urlencoded" }, - body + body: new FormData(e.target) }) .then(res => { if (res.status !== 200) { @@ -232,8 +215,8 @@ export default function Index({ data }) { Describe what needs to be done - - + +