Giter Club home page Giter Club logo

netlify-form-sanity's Introduction

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 to submit data to your Sanity.io project.

Demonstration of Netlify form via Functions to Sanity Studio

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, 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 as the _type: "submission.form", 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:
/*
 * 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' }]
        }
      ]
    }
  ]
}

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.