0

So I am trying to process a form request using the netlify forms. Everything works fine except that the data does not get sent with the form.

So here is the form

<template>
    <form @submit.prevent="handleSubmit" name="Free Assessment Form" method="post" data-netlify-honeypot="bot-field">
      <span class="slogan">{{ slogan }}</span>
      <input type="hidden" name="form-name" value="contact"  class="hidden"/>
      <input @input="ev => formData.business_name = ev.target.value" type="text" name="Business Name" placeholder="Business Name" :class="{'input-error': error}" @change="error = false">
      <input @input="ev => formData.first_name = ev.target.value" type="text" name="First Name" placeholder="First Name" :class="{'input-error': error}" @change="error = false">
      <input @input="ev => formData.last_name = ev.target.value" type="text" name="Last Name" placeholder="Last Name" :class="{'input-error': error}" @change="error = false">
      <input @input="ev => formData.email = ev.target.value" type="email" name="Email" placeholder="Email" :class="{'input-error': error}" @change="error = false">
      <input @input="ev => formData.phone = ev.target.value" type="text" name="Phone Number" placeholder="Phone Number" :class="{'input-error': error}" @change="error = false">
      <button type="submit" class="form-btn">Submit</button>
    </form>
</template>

<script>
export default {
  name: 'Form',
  props: ['slogan'],
    data() {
    return {
      formData: {},
      error: false
    }
  },
  methods: {
    encode(data) {
    return Object.keys(data)
      .map(key => encodeURIComponent(key) + '=' + encodeURIComponent(data[key]))
      .join('&')
    },
    handleSubmit(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.formData = ""
        this.$router.push('/')
        alert('Form Submitted!')
      })
      .catch(error => alert(error))
    }
  }
}
</script>

Now once the form is submitted I receive my email as expected however, the I only get the form keys. I don't receive the form key values.

In my local developement when I console.log the data passed into the encode method, it is all there so I am not understanding why it is not working.

TJ Weems
  • 1,086
  • 3
  • 21
  • 37

0 Answers0