Edit form for netlify

This commit is contained in:
BenRoe 2019-09-03 15:25:39 +02:00
parent ef6d9cb39c
commit b99987171e
2 changed files with 41 additions and 2 deletions

16
src/pages/success.vue Executable file
View File

@ -0,0 +1,16 @@
<template>
<Layout>
<div class="container-inner mx-auto text-center py-16">
<h2 class="text-4xl font-bold">Thanks for contributing</h2>
</div>
</Layout>
</template>
<script>
export default {
metaInfo: {
title: "Form successfuly send"
}
};
</script>

View File

@ -6,10 +6,13 @@
<form
class="w-full max-w-lg"
name="addSwitch"
method="POST"
netlify-honeypot="isRequired"
method="post"
v-on:submit.prevent="handleFormSubmit"
action="/success/"
data-netlify="true"
data-netlify-honeypot="isRequired"
>
<input type="hidden" name="form-name" value="addSwitch" />
<div class="flex flex-wrap -mx-3 mb-6">
<div class="w-full md:w-1/2 px-3 mb-6 md:mb-0">
<label
@ -387,6 +390,7 @@ export default {
return {
perPage: 3,
data: [],
formData: {},
detailRow: SwitchDetailRow,
fields: [
{ name: "id", visible: false },
@ -442,6 +446,25 @@ export default {
.then(response => (this.data = response.data));
},
methods: {
encode(data) {
return Object.keys(data)
.map(
key => encodeURIComponent(key) + "=" + encodeURIComponent(data[key])
)
.join("&");
},
handleFormSubmit(e) {
fetch("/", {
method: "POST",
headers: { "Content-Type": "application/x-www-form-urlencoded" },
body: this.encode({
"form-name": e.target.getAttribute("name"),
...this.formData
})
})
.then(() => this.$router.push("/success"))
.catch(error => alert(error));
},
toggleDetailRow(event) {
this.$refs.vuetable.toggleDetailRow(event.data.id);
},