# π FormHive **Open-source form backend as a service.** Collect form submissions from any website, view them in a beautiful dashboard, get webhook notifications, and block spam β all running on Cloudflare's edge network. A self-hostable alternative to Formspree, Getform, and Basin.    --- ## β¨ Features - **π Simple API** β Point any HTML form or `fetch()` call at your endpoint - **π Dashboard** β Beautiful dark-mode UI to view and manage submissions - **π‘οΈ Spam Filtering** β Honeypot fields + pattern-based detection built in - **π Webhooks** β Get notified on every submission (Slack, Discord, Zapier, etc.) - **β‘ Edge-powered** β Runs on Cloudflare Workers (fast globally, free tier friendly) - **ποΈ D1 Database** β Submissions stored in Cloudflare's serverless SQL - **π API Key Auth** β Secure dashboard access with bearer tokens - **π± Responsive** β Dashboard works on mobile - **π One-click deploy** β Set up in under 5 minutes - **πΈ Free tier** β Cloudflare's free tier covers most use cases ## π Quick Start ### 1. Clone & Setup ```bash git clone https://github.com/kszongic/formhive.git cd formhive npm install -g wrangler wrangler login ``` ### 2. Create D1 Database & KV Namespace ```bash wrangler d1 create formhive-db wrangler kv:namespace create FORMHIVE_KV ``` Update the IDs in `wrangler.toml` with the output values. ### 3. Initialize Database ```bash wrangler d1 execute formhive-db --file=schema.sql ``` ### 4. Deploy ```bash wrangler deploy ``` ### 5. Setup Admin Account ```bash curl -X POST https://your-worker.workers.dev/api/setup \ -H "Content-Type: application/json" \ -d '{"name": "Admin"}' ``` Save the returned API key! You'll need it for the dashboard. ### 6. Open Dashboard Visit `https://your-worker.workers.dev` and enter your API key. --- ## π Usage ### HTML Form ```html
``` ### JavaScript (fetch) ```javascript const response = await fetch('https://your-worker.workers.dev/f/YOUR_FORM_ID', { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ name: 'John Doe', email: 'john@example.com', message: 'Hello from my website!' }) }); const result = await response.json(); // { ok: true, id: "submission-uuid" } ``` ### Special Fields | Field | Purpose | |-------|---------| | `_honeypot`, `_gotcha`, `_hp` | Spam honeypot (bots fill these, humans don't) | | `_redirect` | Override redirect URL for this submission | --- ## π API Reference All dashboard API calls require `Authorization: Bearer YOUR_API_KEY` header. | Method | Endpoint | Description | |--------|----------|-------------| | `POST` | `/api/setup` | First-time admin setup (no auth) | | `POST` | `/f/:formId` | Submit a form (public, no auth) | | `GET` | `/api/stats` | Dashboard statistics | | `GET` | `/api/forms` | List all forms | | `POST` | `/api/forms` | Create a new form | | `GET` | `/api/forms/:id` | Get form details | | `DELETE` | `/api/forms/:id` | Delete form + submissions | | `GET` | `/api/forms/:id/submissions` | List submissions (paginated) | | `DELETE` | `/api/submissions/:id` | Delete a submission | ### Create Form ```bash curl -X POST https://your-worker.workers.dev/api/forms \ -H "Authorization: Bearer fh_xxx" \ -H "Content-Type: application/json" \ -d '{ "name": "Contact Form", "webhook_url": "https://hooks.slack.com/xxx", "redirect_url": "https://mysite.com/thanks" }' ``` --- ## ποΈ Architecture ``` ββββββββββββββββ ββββββββββββββββββββββββ ββββββββββββ β HTML Form ββββββΆβ Cloudflare Worker ββββββΆβ D1 (SQL)β β or fetch() β β - Spam filtering β ββββββββββββ ββββββββββββββββ β - Rate limiting (KV) β ββββββββββββ β - Webhook dispatch ββββββΆβ Webhook β ββββββββββββββββ β - Dashboard API β ββββββββββββ β Dashboard ββββββΆβ - Static site serve β β (SPA) β ββββββββββββββββββββββββ ββββββββββββββββ ``` ## π License MIT β use it however you want. --- **Built with β and Cloudflare Workers.**