Skip to main content
Generate secure, validated HTML forms with built-in CSRF protection, CAPTCHA, rate limiting, and multi-step support.

Overview

The Form operation enables you to:
  • Generate forms declaratively - Define fields in YAML, get production-ready HTML
  • Server-side validation - Built-in validation rules with custom error messages
  • Security features - CSRF tokens, CAPTCHA, honeypot, rate limiting
  • Multi-step forms - Complex workflows with conditional steps
  • Flexible styling - Tailwind, Bootstrap, or custom CSS
  • Type-safe - Full TypeScript support

Quick Start

Simple Contact Form

Field Types

The Form operation supports all standard HTML5 input types:

Text Inputs

Email

Password

Number

Tel (Phone)

URL

Textarea

Select (Dropdown)

Checkbox

Radio Buttons

Date & Time

File Upload

Hidden Fields

Validation Rules

Built-in Validators

Multi-Step Forms

For complex workflows, use multi-step forms:

Security Features

CSRF Protection

Prevent cross-site request forgery attacks:
The CSRF token is automatically:
  • Generated on form render
  • Included as a hidden field
  • Validated on form submission

CAPTCHA Integration

Protect against bots with CAPTCHA:
Supported CAPTCHA types:
  • turnstile - Cloudflare Turnstile (recommended for Cloudflare Workers)
  • recaptcha - Google reCAPTCHA v2/v3
  • hcaptcha - hCaptcha

Honeypot Field

Catch bots with invisible honeypot field:
The honeypot field is:
  • Hidden with CSS
  • Automatically validated (should be empty)
  • Rejects submissions if filled out

Rate Limiting

Prevent spam and abuse:

Styling and Theming

Tailwind CSS

Bootstrap

Custom CSS

Form Modes

The Form operation has three modes:

1. Render Mode (Default)

Generate form HTML:
Output:

2. Validate Mode

Validate form data without processing:
Output:

3. Submit Mode

Validate and process submission:
Output:

Complete Example: Contact Form with Security

Integration with Ensembles

Render and Process Flow

Best Practices

1. Always Enable CSRF Protection

2. Use Rate Limiting for Public Forms

3. Add CAPTCHA for High-Value Forms

4. Validate on Server-Side

Never trust client-side validation alone. Always validate on submission:

5. Provide Clear Error Messages

6. Use Appropriate Field Types

Troubleshooting

Form Not Rendering

Issue: Form HTML is empty or undefined Solution: Check that form config has either fields or steps:

Validation Errors Not Showing

Issue: Validation runs but errors aren’t displayed Solution: Ensure mode is set correctly:

CSRF Token Invalid

Issue: Form submission fails with CSRF error Solution: Ensure CSRF secret is configured and consistent:

Rate Limit Not Working

Issue: Users can submit multiple times rapidly Solution: Ensure rate limit KV namespace is bound:

Next Steps

HTML Operation

Generate custom HTML

Email Operation

Send emails with forms

Storage Operation

Save form data to database

Code Operation

Custom form processing