Hello I am looking for some help implementing netlify forms with my sapper app. I got the response to send - but the values don’t seem to be bound correctly.
<script>
let form = {
// checkbox
services: [""],
// text
firstName: "",
lastName: "",
phone: "",
email: "",
// textarea
message: ""
};
const encode = (data) => {
return Object.keys(data)
.map(key => encodeURIComponent(key) + "=" + encodeURIComponent(data[key]))
.join("&");
}
function handleSubmit() {
fetch("/", {
method: "POST",
headers: { "Content-Type": "application/x-www-form-urlencoded" },
body: encode({ "form-name": "contact", ...formData })
})
.then(() => alert("Success!"))
.catch(error => alert(error));
};
</script>
<input
type="checkbox"
name="choice1"
bind:group={form.services}
value="chioce1" />
<input
type="checkbox"
name="choice2"
bind:group={form.services}
value="choice2" />
...
<input type="text" name="phone" bind:value={form.phone} />
....
<textarea name="message" bind:value={form.message} />