# gforms-submit

> Submit form data to Google Forms via JavaScript/TypeScript.

Latest version **1.0.5** (published 2019-06-02) · ISC license · 0 weekly downloads

> **Deprecated.** This package is deprecated.

## Install

```sh
npm install gforms-submit
pnpm add gforms-submit
yarn add gforms-submit
bun add gforms-submit
```

## Health

**Score 10/100 (F)** — status: deprecated.

Negative: deprecated.

## Facts

| | |
|---|---|
| Version | 1.0.5 |
| Published | 2019-06-02 |
| First published | 2019-06-02 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 2 |
| Unpacked size | 66.7 KB |
| Known vulnerabilities | 0 (+25 in 1 direct dependencies) |
| Install scripts | no |
| Author | Justin Mahar |
| Maintainers | justinmahar |
| Keywords | Google Forms, contact form, feedback form, mailing list, GForms |

## Links

- npm: https://www.npmjs.com/package/gforms-submit
- Repository: https://github.com/justinmahar/gforms-submit
- Homepage: https://github.com/justinmahar/gforms-submit#readme
- Issues: https://github.com/justinmahar/gforms-submit/issues
- npm.io page: https://npm.io/package/gforms-submit

## Dependencies (2)

- [axios](https://npm.io/package/axios.md) ^0.19.0
- [form-data](https://npm.io/package/form-data.md) ^2.3.3

## Alternatives

- [@expo/fingerprint](https://npm.io/package/@expo/fingerprint.md) — 6.2M weekly downloads
- [@azure/monitor-opentelemetry-exporter](https://npm.io/package/@azure/monitor-opentelemetry-exporter.md) — 850.0K weekly downloads
- [@azure/monitor-opentelemetry](https://npm.io/package/@azure/monitor-opentelemetry.md) — 624.0K weekly downloads
- [@posthog/ai](https://npm.io/package/@posthog/ai.md) — 423.3K weekly downloads
- [fakefilter](https://npm.io/package/fakefilter.md) — 63.9K weekly downloads

## Recent versions

- 1.0.5 (latest) — 2019-06-02
- 1.0.4 — 2019-06-02
- 1.0.3 — 2019-06-02
- 1.0.2 — 2019-06-02
- 1.0.1 — 2019-06-02
- 1.0.0 — 2019-06-02

## README

# GForms Submit

Submit form data to Google Forms via JavaScript/TypeScript.

This project can be used to build simple serverless contact forms and mailing lists with very little overhead.

## Installation

```bash
npm i gforms-submit
```

## Usage

Create a new [Google Form](http://forms.google.com), click Preview, inspect the DOM, and retrieve the `<form>` action URL and form field `name=` attribute values from your Google Form.

```js
import gformsSubmit from "gforms-submit";

// Replace this with your form's action URL
const gformActionUrl =
  "https://docs.google.com/forms/d/e/abcdefgh12345678-abcdefgh/formResponse";

// Replace the name attribute with your form's
const emailFormField = {
  nameAttribute: "emailAddress",
  value: "test@example.com"
};

// Replace the name attribute with your form's
const messageFormField = {
  nameAttribute: "entry.12345678901",
  value: "Hello! This is my message."
};

// You can have as many form fields as you'd like!
const formFields = [emailFormField, messageFormField];

gformsSubmit(gformActionUrl, formFields)
  .then(() => {
    console.log("Sent!");
  })
  .catch(err => {
    console.log(err);
  });
```

## CORS

Responses from Google's servers are blocked by modern browsers due to CORS restrictions. Because of this, there's no way to know whether or not the form submission succeeded, so all submissions are treated as successful. You will see a CORS error in the console, but the form will still receive the submission.

If you use/build a CORS proxy, you can turn on error handling for your request to the proxy server. Error responses can then be handled as you see fit.

You can specify `handleErrors` to turn on request error handling:

```js
// ...
const handleErrors = true;
// Note: This will always fail if you're not using a proxy!
gformsSubmit(gformActionUrl, formFields, handleErrors)
  .then(() => {
    console.log("Sent!");
  })
  .catch(err => {
    console.log(err);
  });
```

## Axios

This project uses [`axios`](https://www.npmjs.com/package/axios) to make requests.

## TypeScript Support

This project is written in TypeScript and compiled to JavaScript. Type definitions are available in `dist/index.d.ts`.

Form fields are defined as type `GFormField`, like so:

```ts
import gformsSubmit, { GFormField } from "gforms-submit";

const emailFormField: GFormField = {
  nameAttribute: "emailAddress",
  value: "test@example.com"
};
```

## ISC License

Copyright 2019 Justin Mahar

Permission to use, copy, modify, and/or distribute this software for any purpose with or without fee is hereby granted, provided that the above copyright notice and this permission notice appear in all copies.

THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.

---
_Source: https://npm.io/package/gforms-submit · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
