An open API service indexing awesome lists of open source software.

https://github.com/bkwld/vue-netlify-form

Renders a form element for use with Netlify Forms that validates Netlify conventions and handles submission.
https://github.com/bkwld/vue-netlify-form

form netlify vue

Last synced: 2 months ago
JSON representation

Renders a form element for use with Netlify Forms that validates Netlify conventions and handles submission.

Awesome Lists containing this project

README

          

# vue-netlify-form

This component was created to simplify submission to [Netlify Forms](https://docs.netlify.com/forms) and help catch common mistakes.

## Features

- Validates presence of form and field names. Form name is a required prop. The presence of field names is validated during development (by checking `NODE_ENV != "production`) and emits a console warning like `Missing Netlify form field named: Email` if a form field lacks a name.
- Submits form data to Netlify using [@nuxt/axios](https://axios.nuxtjs.org/).
- Passes form lifecycle state through scoped slots.

## Usage

```vue


Thanks for your submission


{{ submitting ? 'Submitting' : 'Submit' }}


export default {
data: function() {
form: {
Email: ''
}
}
}

```

## Props

| Name | Default | Description |
| ---- | ------- | ----------- |
| `name` | _required_ | The name of the form. This will be how the form shows up within the Netlify Forms dashboard |
| `form` | _required_ | The form data as key/value pairs. This is what your form fields are updating on input. You may want to title case the keys as these are what are displayed within the Netlify Forms dashboard |
| `endpoint` | `/` | Where the form should submit to. On production, the form should POST to the root of your site. While dev-ing locally, you may want to pass the hostname of your Netlify app here so you can post to it from your localhost. This also reads from `process.env.NETLIFY_FORMS_ENDPOINT`. |

## Notes

#### CORS when using `endpoint`

If you're going to use the `endpoint` prop to submit to your production endpoint from localhost, you should add something like the following to `_headers` to allow those requests.

```
/
Access-Control-Allow-Origin: http://localhost:3000
Access-Control-Allow-Methods: POST
Access-Control-Allow-Headers: content-type
```