Skip to content

Add Form component - #302

Open
bazottie wants to merge 36 commits into
mainfrom
feat/forms
Open

bazottie wants to merge 36 commits into
mainfrom
feat/forms

Conversation

@bazottie

@bazottie bazottie commented Sep 11, 2025

Copy link
Copy Markdown
Member

Large parts are copied from projects by @jurgenbelien and @velomovies

Changes

  • Adds a Form component
  • Adds a Form Block
  • Adds Forms field with little bit of logic in dato
    • text, email, phone, number, date, textarea, select, radio, checkbox
  • Adds server side form validation with API route
  • Form submissions is another ticket Transactional emails #112
  • Adds success, error and not found page for form submissions
  • Adds Spam protection via Cloudflare Turnstile

Associated issue

#113

How to test

  1. Open preview link
  2. Navigate to /demos/form-block-demo/
  3. Fill in the form a couple of times, see f it works like you expect it to do.
  4. Modify the form in dato to check if the form changes like you expect it to do.
  5. Submitting the form now shows you an error page because the turnstile keys are not set yet.
  6. Locally it shows an error page when something goes wrong in the form. And an inline error when something goes wrong validating the form values.

Checklist

  • I have performed a self-review of my own code
  • I have made sure that my PR is easy to review (not too big, includes comments)
  • I have made updated relevant documentation files (in project README, docs/, etc)
  • I have added a decision log entry if the change affects the architecture or changes a significant technology
  • I have notified a reviewer

@bazottie bazottie changed the title Add form components, api routes, and migrations Add Form component Sep 11, 2025
@cloudflare-workers-and-pages

cloudflare-workers-and-pages Bot commented Sep 11, 2025

Copy link
Copy Markdown

Deploying head-start with  Cloudflare Pages  Cloudflare Pages

Latest commit: 56e410d
Status: ✅  Deploy successful!
Preview URL: https://baceb638.head-start.pages.dev
Branch Preview URL: https://feat-forms.head-start.pages.dev

View logs

@JopMolenaar
JopMolenaar marked this pull request as ready for review June 24, 2026 09:22
Copilot AI review requested due to automatic review settings June 24, 2026 09:22

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR introduces a CMS-driven “Form” capability to Head Start: a new Form component + FormBlock, a DatoCMS schema/migration for form definitions, and an API route that validates submissions (with Cloudflare Turnstile support).

Changes:

  • Adds a new Forms content collection (DatoCMS GraphQL + Astro content loader) and a FormBlock to render a referenced form by slug.
  • Adds server-side form validation + per-form action handlers under /api/forms/[slug]/.
  • Adds Turnstile integration and client-side progressive enhancement for inline error rendering.

Reviewed changes

Copilot reviewed 38 out of 39 changed files in this pull request and generated 19 comments.

Show a summary per file
File Description
src/pages/api/forms/[slug]/index.ts New POST endpoint for form validation + dispatch to per-form action module
src/pages/api/forms/[slug]/_contact.ts Example form action handler returning a success view
src/pages/[locale]/_index.query.graphql Adds FormBlock fragment inclusion on home page query
src/lib/renderer/index.ts Import order tweak + adds renderToResponse helper
src/lib/forms/validate.ts Implements server-side validation + Turnstile gating
src/lib/forms/turnstile.ts Implements Turnstile /siteverify call
src/lib/forms/index.ts Exposes form helpers from src/lib/forms/*
src/content/Pages/CollectionEntry.query.graphql Adds FormBlock fragment inclusion for pages
src/content/PagePartials/CollectionEntry.query.graphql Adds FormBlock fragment inclusion for page partials
src/content/Forms/index.ts New Astro content collection loader for Forms
src/content/Forms/CollectionEntry.query.graphql GraphQL query for a single Form record
src/content/config.ts Registers the new Forms collection
src/components/FormField/FormField.astro Renders individual fields and groups (fieldset for checkbox/radio)
src/components/FormField/fieldTypes.ts Defines supported field types and a type guard
src/components/FormField/Fields/Textarea.astro Textarea field component
src/components/FormField/Fields/Select.astro Select field component
src/components/FormField/Fields/RadioGroup.astro Radio group renderer
src/components/FormField/Fields/Input.astro Input field component
src/components/FormField/Fields/Fieldset.astro Wrapper for checkbox/radio groups
src/components/FormField/Fields/CheckboxGroup.client.ts Web component to enforce “at least one required” for checkbox groups
src/components/FormField/Fields/CheckboxGroup.astro Checkbox group renderer + client script include
src/components/Form/Turnstile.astro Turnstile widget markup injection
src/components/Form/index.ts Component barrel exports for Form views
src/components/Form/FormSuccess.astro Success view
src/components/Form/FormNotFound.astro Not-found view
src/components/Form/FormError.astro Error view
src/components/Form/Form.test.ts Unit tests for Form rendering + API behavior
src/components/Form/Form.astro Form renderer (fields + submit + Turnstile + error template)
src/blocks/FormBlock/README.md Documentation for the new FormBlock
src/blocks/FormBlock/FormBlock.fragment.graphql GraphQL fragment for the FormBlock
src/blocks/FormBlock/FormBlock.astro Block implementation resolving Form entry and rendering <web-form>
src/blocks/FormBlock/Form.client.ts Client-side enhancement: AJAX submit + inline errors + Turnstile gating
src/blocks/blocksByTypename.ts Registers FormBlockRecord mapping
env.d.ts Adds Turnstile env vars typing
datocms-environment.ts Changes the configured DatoCMS environment
config/datocms/migrations/1780562401_featForms.ts Migration adding Form models/blocks and wiring them into page body blocks
astro.config.ts Adds Turnstile env schema entries
.github/workflows/node-ci.yml Adds Turnstile env vars to CI environment
.env.example Adds Turnstile env var placeholders

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread datocms-environment.ts
* @see docs/decision-log/2023-10-24-datocms-env-file.md on why file is preferred over env vars
*/
export const datocmsEnvironment = 'deploy-search-form';
export const datocmsEnvironment = 'dev-sandbox-21-05';
Comment thread config/datocms/migrations/1780562401_featForms.ts
Comment thread config/datocms/migrations/1780562401_featForms.ts
Comment thread src/blocks/FormBlock/README.md
Comment thread src/pages/api/forms/[slug]/index.ts Outdated
Comment thread src/blocks/FormBlock/Form.client.ts
Comment thread src/blocks/FormBlock/Form.client.ts
Comment thread src/components/Form/Form.astro
Comment thread src/lib/forms/index.ts Outdated
Comment thread src/lib/forms/validate.ts
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants