File tree Expand file tree Collapse file tree 1 file changed +76
-0
lines changed Expand file tree Collapse file tree 1 file changed +76
-0
lines changed Original file line number Diff line number Diff line change 1+ # How to use Netlify Form and Functions to submit data to Sanity.io
2+
3+ 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.
4+
5+ ## How to use
6+
7+ 1 . Fork or clone this repo
8+ 2 . Run ` yarn ` or ` npm install `
9+ 3 . Change the ` projectId ` and the ` dataset ` configuration in ` /lambda/submission-created.js ` to your Sanity.io project`s
10+ 4 . Commit and push the changes to your GitHub repo
11+ 5 . Connect Netlify to that repo, and add a environment variable in Netlify called ` SANITY_TOKEN `
12+ 6 . Go to your Settings -> API in your project at [ manage.sanity.io] ( https://manage.sanity.io ) , and add a token with ` write ` rights.
13+ 7 . Paste this token as the value for ` SANITY_TOKEN ` (be careful with where you store this token!)
14+ 8 . Submissions will be stored as the ` _type: "submission.form" ` , and will not be available through the public API without a token with ` read ` rights.
15+ 9 . If you want to view the submissions in the Studio, you can add the following schema to your project:
16+
17+ ``` js
18+ /*
19+ * Doesn't cover all the data fields.
20+ * Remove or sest readOnly to `false` if you want to be able
21+ * to edit the responses in the Studio
22+ */
23+
24+ export default {
25+ name: ' submission.form' ,
26+ type: ' document' ,
27+ title: ' Form submission' ,
28+ readOnly: true ,
29+ fields: [
30+ {
31+ name: ' title' ,
32+ type: ' string' ,
33+ title: ' Title'
34+ },
35+ {
36+ name: ' number' ,
37+ type: ' number' ,
38+ title: ' Number'
39+ },
40+ {
41+ name: ' created_at' ,
42+ type: ' datetime' ,
43+ title: ' Created at'
44+ },
45+ {
46+ name: ' data' ,
47+ type: ' object' ,
48+ title: ' Data' ,
49+ fields: [
50+ {
51+ name: ' email' ,
52+ type: ' email' ,
53+ title: ' Email'
54+ },
55+ {
56+ name: ' name' ,
57+ type: ' string' ,
58+ title: ' Name'
59+ },
60+ {
61+ name: ' message' ,
62+ type: ' text' ,
63+ title: ' Message'
64+ },
65+ {
66+ name: ' role' ,
67+ type: ' array' ,
68+ title: ' Role' ,
69+ of: [{ type: ' string' }]
70+ }
71+ ]
72+ }
73+ ]
74+ }
75+
76+ ```
You can’t perform that action at this time.
0 commit comments