@webadeva/use-easy-google-form
v3.0.2
Published
Easily post google forms using react hook
Maintainers
Readme
use-easy-google-form
Use your own React form UI and let Google Forms quietly handle the collection work behind the scenes.
use-easy-google-form is a lightweight React hook that maps fields from your custom form to a Google Form and submits them for you. In short: you keep the nice frontend, Google keeps the spreadsheet, and nobody has to wrestle with the default Google Form styling unless they want to.
Why use it?
- Keep your own branded or custom React form UI.
- Submit responses directly to Google Forms without building a backend.
- Store data in the Google Forms / Google Sheets workflow you already know.
- Set it up with one hook, one
formRef, and a simple field mapping.
Requirements
Runtime requirements
react >= 16react-dom >= 16- A browser environment with
fetch - An existing Google Form with the fields already created
- A Google Form that is public and accepting responses (not restricted by sign-in or organization-only access)
Local development requirements
node >= 20npm >= 9orpnpm
Currently unsupported Google Form question types:
File upload,Grid, andScale.
Installation
pnpm add @webadeva/use-easy-google-formOr with npm:
npm install @webadeva/use-easy-google-formOr with Yarn:
yarn add @webadeva/use-easy-google-formQuick start
import { useRef } from "react";
import useEasyGoogleForm from "@webadeva/use-easy-google-form";
export function ContactForm() {
const formRef = useRef<HTMLFormElement>(null);
const onSubmit = useEasyGoogleForm({
gFormId: "1FAIpQLSdYourGoogleFormIdHere",
formRef,
links: [
{ entryId: "entry.111111111", formId: "name", type: "text" },
{ entryId: "entry.222222222", formId: "message", type: "textarea" },
{ entryId: "entry.333333333", formId: "topic", type: "dropdown" },
],
onSubmitExtra: () => {
alert("Submitted. Google is now doing the paperwork.");
},
});
return (
<form ref={formRef} onSubmit={onSubmit}>
<input id="name" placeholder="Your name" />
<textarea id="message" placeholder="Your message" />
<select id="topic" defaultValue="General">
<option value="General">General</option>
<option value="Support">Support</option>
</select>
<button type="submit">Send</button>
</form>
);
}API
useEasyGoogleForm(params)
Returns an onSubmit handler you can pass directly to your <form> element.
Parameters
| Name | Type | Required | Description |
| --------------- | ---------------------------------- | -------- | ---------------------------------------------------------------------- |
| gFormId | string | Yes | The Google Form ID from the form URL. |
| formRef | RefObject<HTMLFormElement> | Yes | A React ref pointing to your form element. |
| links | Array<{ entryId, formId, type }> | Yes | Maps your form fields to Google Form entries. |
| extraEntries | Array<{ entryId, value }> | No | Adds extra fixed values that are not directly present in your form UI. |
| onSubmitExtra | SubmitEventHandler<HTMLElement> | No | Runs after the hook finishes its submit logic. |
links object shape
Each item in links must include:
entryId: the Google Form field name, usually something likeentry.123456789formId: theidof the element in your own formtype: one of the supported input types:texttextarearadiocheckboxdatedropdowntime
Field mapping reference
| Type | Target element in your form | How the hook reads the value |
| ---------- | ------------------------------------------ | -------------------------------------------------------------------- |
| text | input | Reads #yourId.value |
| textarea | textarea | Reads #yourId.value |
| radio | Container element (div, section, etc.) | Finds input:checked inside the container |
| checkbox | Container element (div, section, etc.) | Finds all input:checked inside the container |
| dropdown | select | Reads select#yourId.value |
| date | Container element | Looks for child inputs named day, month, and optional year |
| time | Container element | Looks for child inputs named hour, minute, and optional second |
Special notes for date and time
For date fields, the inputs inside the container should use the following name attributes:
daymonthyear(optional if your Google Form does not need it)
For time fields, use:
hourminutesecond(optional, mainly for duration-style inputs)
How to connect your Google Form
Recommended first: if you want less inspecting, less copy-pasting, and fewer "where did this
entryIdcome from?" moments, try the companion browser extension: useEasyGoogleForm extensionIt can generate a React form component from your Google Form page and makes setup much faster.
If you want to wire things up manually, here is the usual process:
Create your Google Form and add the questions you need.
Open the form menu and choose Get pre-filled link.
Inspect the generated page and find the input
namevalues that look likeentry.123456789.Copy your Google Form ID from the URL:
https://docs.google.com/forms/d/<gFormId>/viewformMap each Google
entryIdto the matching elementidin your React form.
If you want a helpful visual reference for the pre-filled-link approach, this article is still handy: Let’s auto fill Google Forms with URL parameters.
Tips and troubleshooting
- If submissions are not showing up, double-check that your
entryIdvalues are correct. - Make sure the target Google Form is public and currently accepting responses. If it is locked behind sign-in or restricted to a private organization, this library will not be able to submit to it.
- For
radioandcheckbox, make sure the checked inputs live inside the container with the matchingformId. - For
dateandtime, verify the child inputs use the exact requirednameattributes. - If you are debugging, start with one field first, confirm it works, then add the rest. Future-you will be grateful.
Development
pnpm install
pnpm build
pnpm lint