Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/sanity-io/netlify-form-sanity
How to use Netlify Forms and Functions to submit data to Sanity.io
https://github.com/sanity-io/netlify-form-sanity
api headless-cms netlify netlify-forms netlify-functions sanity sanity-io serverless
Last synced: 13 days ago
JSON representation
How to use Netlify Forms and Functions to submit data to Sanity.io
- Host: GitHub
- URL: https://github.com/sanity-io/netlify-form-sanity
- Owner: sanity-io
- Created: 2019-01-27T11:32:47.000Z (almost 6 years ago)
- Default Branch: master
- Last Pushed: 2022-10-28T00:17:30.000Z (about 2 years ago)
- Last Synced: 2024-07-31T20:28:25.841Z (3 months ago)
- Topics: api, headless-cms, netlify, netlify-forms, netlify-functions, sanity, sanity-io, serverless
- Language: HTML
- Homepage: https://www.sanity.io
- Size: 134 KB
- Stars: 46
- Watchers: 3
- Forks: 15
- Open Issues: 10
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
- awesome-sanity - Netlify from Sanity - How to use Netlify Forms and Functions to submit data to Sanity.io (Sample projects / How-to's)
README
# How to use Netlify Forms and Functions to submit data to Sanity.io
This is a simple example of how you can use Forms and Functions in [Netlify](https://netlify.com) to submit data to your Sanity.io project.
![Demonstration of Netlify form via Functions to Sanity Studio](https://cdn.sanity.io/images/3do82whm/production/1728e9c2e1a25edbbb914e53edff8ded40ed2567-1642x1056.gif)
## How to use
1. Fork or clone this repo
2. Run `yarn` or `npm install`
3. Change the `projectId` and the `dataset` configuration in `/lambda/submission-created.js` to your Sanity.io project`s
4. Commit and push the changes to your GitHub repo
5. Connect Netlify to that repo, and add a environment variable in Netlify called `SANITY_TOKEN`
6. Go to your Settings -> API in your project at [manage.sanity.io](https://manage.sanity.io), and add a token with `write` rights.
7. Paste this token as the value for `SANITY_TOKEN` (be careful with where you store this token!)
8. Submissions will be stored with `_id` on [a path](https://www.sanity.io/docs/ids): `"submission."`, and will not be available through the public API without a token with `read` rights.
9. If you want to view the submissions in the Studio, you can add the following schema to your project:```js
/*
* Doesn't cover all the data fields.
* Remove or set readOnly to `false` if you want to be able
* to edit the responses in the Studio
*/export default {
name: 'submission.form',
type: 'document',
title: 'Form submission',
readOnly: true,
fields: [
{
name: 'title',
type: 'string',
title: 'Title'
},
{
name: 'number',
type: 'number',
title: 'Number'
},
{
name: 'created_at',
type: 'datetime',
title: 'Created at'
},
{
name: 'data',
type: 'object',
title: 'Data',
fields: [
{
name: 'email',
type: 'email',
title: 'Email'
},
{
name: 'name',
type: 'string',
title: 'Name'
},
{
name: 'message',
type: 'text',
title: 'Message'
},
{
name: 'role',
type: 'array',
title: 'Role',
of: [{ type: 'string' }]
}
]
}
]
}```