Skip to content
Free · No sign-up · Nothing stored

Free online form builder for Bootstrap and Tailwind

Drag fields onto the form, try it in the preview, then copy the code: paste one snippet into your page and put the ready server code for PHP, Node.js, ASP.NET Core or Python where the form is sent.

  • Drag and drop21 field types, columns, undo and redo. Mouse, touch and keyboard.
  • Your frameworkBootstrap 5, Bootstrap 6, Tailwind CSS or plain HTML.
  • Conditions and stepsShow fields based on answers; split long forms into steps.
  • Server code includedPHP, Node.js, ASP.NET Core and Python, made for your form.
  • PrivateIt runs in your browser; the answers go to your own server.

Form builder

Drag fields onto the form and click one to edit it. Preview lets you fill it in, Get code gives the embed code, plain HTML and the server code, and JSON saves the form to load it again later. Nothing you build or type leaves your browser.

Add the form to your site in three steps

No plugin, no account and no monthly fee. The form runs on your site and sends to your server.

1. Build and try it

Drag the fields you need, set what is required, add conditions or steps, and fill it in on the Preview tab.

2. Paste the embed code

Get code, Embed: one snippet with your form and the free WDS Forms script. Paste it into your page where the form should appear.

3. Put the server code

Get code, Server code: pick PHP, Node.js, ASP.NET Core or Python. It checks the answers again and replies to the form; add your email or database code.

Everything a form needs

From the builder to the server: all of it is free.

Drag and drop

Drag fields from the list to the exact place in the form, and drag them again to reorder. Click or tap to add at the end.

21 field types

Text, email, phone, number, password, website, text area, dropdown, radio, checkboxes, switch, date, time, file, slider, hidden and layout blocks.

Columns

Give fields a width from a quarter to full width. Columns stack on phones.

Settings for every field

Label, name, placeholder, help text, default value, required, length, pattern, file types, size limit and more.

Conditional fields

Show a field only when other answers match, with all or any rules. Hidden fields are skipped.

Multi-step forms

Page breaks turn a long form into steps with a progress bar, checked step by step.

Validation

Required, email, web address, phone, min and max, length, pattern, file size and type, with clear messages.

Sends without reloading

The answers go to your address as form data with files, or as JSON. Server errors appear at the fields.

PHP form handler

One file for PHP 8: checks the answers, accepts uploads and replies with JSON or a simple page.

Node.js, ASP.NET Core, Python

The same handler for Express, a .NET minimal API and Flask, made from your form.

Bootstrap 5 and 6

Real Bootstrap markup: form-control and form-check for 5, form-field and the new check, radio and switch for 6.

Tailwind CSS

Clean utility classes for Tailwind v4, with the browser build or your own.

Plain HTML too

Copy the form or a whole page as HTML that works without JavaScript.

Save as JSON

Download the form as JSON and load it again later to change it. Nothing is stored by us.

Accessible

Labels, fieldsets, aria-invalid, linked error messages and focus on the first error.

Open source script

The script that runs your forms is MIT licensed, about 11 KB gzipped, with no dependencies.

Embed code

The Embed code holds your form as JSON in a data-wds-form element, plus one script tag. When the page loads, the script turns the JSON into the form, so there is no script of your own to write and it works with a strict Content Security Policy. This is the code for the contact form in the examples:

<!-- Contact us: made with WDS Forms, https://webdevsnippets.com/wds-forms -->
<!-- Bootstrap 5 CSS: leave this out if your page already loads it -->
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.8/dist/css/bootstrap.min.css">

<div data-wds-form data-theme="bootstrap5">
  <script type="application/json">
    {
      "version": 1,
      "title": "Contact us",
      "description": "We usually answer within one working day.",
      "fields": [
        {
          "id": "f1",
          "type": "text",
          "name": "name",
          "label": "Name",
          "required": true,
          "width": 6,
          "autocomplete": "name"
        },
        {
          "id": "f2",
          "type": "email",
          "name": "email",
          "label": "Email",
          "required": true,
          "width": 6,
          "autocomplete": "email"
        },
        {
          "id": "f3",
          "type": "select",
          "name": "topic",
          "label": "Topic",
          "placeholder": "Choose…",
          "required": true,
          "options": [
            {
              "label": "Sales",
              "value": "sales"
            },
            {
              "label": "Support",
              "value": "support"
            },
            {
              "label": "Other",
              "value": "other"
            }
          ]
        },
        {
          "id": "f4",
          "type": "text",
          "name": "order",
          "label": "Order number",
          "placeholder": "WDS-12345",
          "required": true,
          "pattern": "WDS-\\d{5}",
          "patternMessage": "Use the format WDS-12345.",
          "showIf": {
            "logic": "all",
            "rules": [
              {
                "field": "topic",
                "op": "eq",
                "value": "support"
              }
            ]
          }
        },
        {
          "id": "f5",
          "type": "textarea",
          "name": "message",
          "label": "Message",
          "rows": 5,
          "required": true,
          "minLength": 10,
          "maxLength": 2000
        },
        {
          "id": "f6",
          "type": "file",
          "name": "attachment",
          "label": "Attachment",
          "accept": ".pdf,.jpg,.png",
          "maxSize": 5,
          "help": "PDF, JPG or PNG, up to 5 MB."
        },
        {
          "id": "f7",
          "type": "checkbox",
          "name": "privacy",
          "label": "I agree that my message is stored to answer it",
          "required": true
        }
      ],
      "settings": {
        "action": "/contact",
        "submitText": "Send message",
        "successMessage": "Thank you! We will answer within one working day."
      }
    }
  </script>
</div>

<!-- WDS Forms (free, MIT): turns the JSON above into the form, checks it and sends it -->
<script src="https://cdn.jsdelivr.net/npm/wds-forms@1/dist/wds-forms.min.js" defer></script>

Paste it into any page: plain HTML, WordPress (in a Custom HTML block), Razor, Blade, React or a site builder that accepts HTML. If your page already loads Bootstrap, leave out the stylesheet line.

Sending the answers

Set the address in Get code (Send the answers to) or in the form settings. The form sends to it without leaving the page: as form data with the uploaded files, or as JSON when Send as is JSON. While it sends, the button is disabled; then the form shows your thank-you message and clears itself. Your server replies like this, and the server code does it for you:

200 OK                     { "ok": true }                      the form shows its thank-you message
422 Unprocessable Content  { "errors": { "email": "…" } }      the messages appear at the fields
any other status                                               the form shows its error message

Fields hidden by a condition are not sent. A form on another domain than its server needs CORS headers on the server.

Server code: PHP, Node.js, ASP.NET Core and Python

The Server code in the builder is made for your form. It reads the answers (form data, files and JSON), checks every field again with the same rules as the browser, skips the fields hidden by their conditions, accepts only the listed options and file types, and replies with { "ok": true } or 422 { "errors": … }. A form sent without JavaScript gets a small page instead. The comment The answers are valid marks where to save or email them. This is the code for the contact form above:

One file for PHP 8 or later, no framework and no Composer packages. Upload it and send the form to its address, for example /form-handler.php.

<?php
// Form handler for "Contact us", made with WDS Forms (https://webdevsnippets.com/wds-forms).
// It checks every answer again on the server (never trust the browser alone), then replies with JSON for the
// WDS Forms script, or with a small page for forms sent without JavaScript. Needs PHP 8 or later.
declare(strict_types=1);

const FIELDS = [
    ['name' => 'name', 'type' => 'text', 'label' => 'Name', 'required' => true],
    ['name' => 'email', 'type' => 'email', 'label' => 'Email', 'required' => true],
    ['name' => 'topic', 'type' => 'select', 'label' => 'Topic', 'required' => true, 'options' => ['sales', 'support', 'other']],
    ['name' => 'order', 'type' => 'text', 'label' => 'Order number', 'required' => true, 'pattern' => 'WDS-\\d{5}', 'patternMessage' => 'Use the format WDS-12345.', 'showIf' => ['logic' => 'all', 'rules' => [['field' => 'topic', 'op' => 'eq', 'value' => 'support']]]],
    ['name' => 'message', 'type' => 'textarea', 'label' => 'Message', 'required' => true, 'minLength' => 10, 'maxLength' => 2000],
    ['name' => 'attachment', 'type' => 'file', 'label' => 'Attachment', 'accept' => '.pdf,.jpg,.png', 'maxSize' => 5],
    ['name' => 'privacy', 'type' => 'checkbox', 'label' => 'I agree that my message is stored to answer it', 'required' => true]
];

const MESSAGES = [
    'required' => 'This field is required.',
    'requiredCheck' => 'Please check this box.',
    'requiredChoice' => 'Please choose an option.',
    'requiredFile' => 'Please choose a file.',
    'email' => 'Enter a valid email address.',
    'url' => 'Enter a valid web address, starting with http:// or https://.',
    'tel' => 'Enter a valid phone number.',
    'number' => 'Enter a number.',
    'min' => 'Enter {min} or more.',
    'max' => 'Enter {max} or less.',
    'minDate' => 'Choose {min} or later.',
    'maxDate' => 'Choose {max} or earlier.',
    'minLength' => 'Enter at least {min} characters.',
    'maxLength' => 'Enter at most {max} characters.',
    'pattern' => 'The value is not in the expected format.',
    'fileSize' => 'Each file must be {max} MB or smaller.',
    'fileType' => 'This file type is not allowed.',
    'success' => 'Thank you! We will answer within one working day.',
    'fix' => 'Please correct these fields:',
    'back' => 'Go back to the form'
];

if ($_SERVER['REQUEST_METHOD'] !== 'POST') {
    http_response_code(405);
    exit;
}

$values = wdsf_values();
$visible = wdsf_visible($values);
$values = array_intersect_key($values, array_flip($visible)); // fields hidden by their conditions are left out
$errors = wdsf_validate($values, $visible);
$wantsJson = str_contains($_SERVER['HTTP_ACCEPT'] ?? '', 'application/json');

if ($errors) {
    http_response_code(422);
    if ($wantsJson) {
        header('Content-Type: application/json');
        echo json_encode(['errors' => $errors]);
    } else {
        wdsf_page('<p>' . htmlspecialchars(MESSAGES['fix']) . '</p><ul>' . implode('', array_map(
            fn ($name, $error) => '<li>' . htmlspecialchars(wdsf_label($name) . ': ' . $error) . '</li>',
            array_keys($errors),
            $errors
        )) . '</ul>');
    }
    exit;
}

// ---------- The answers are valid: save them or email them here. ----------
// $values holds the answers by field name. wdsf_summary($values) gives them as "Label: answer" lines.
// Email them to yourself (needs a working mail setup on your server):
// mail('you@example.com', 'New form: Contact us', wdsf_summary($values));
// Keep an uploaded file (make the uploads folder first, outside the web root if you can):
// foreach ($values['attachment'] as $file) {
//     move_uploaded_file($file['tmp_name'], __DIR__ . '/uploads/' . bin2hex(random_bytes(8)) . '-' . basename($file['name']));
// }

if ($wantsJson) {
    header('Content-Type: application/json');
    echo json_encode(['ok' => true]);
} else {
    wdsf_page('<p>' . htmlspecialchars(MESSAGES['success']) . '</p>');
}

// ---------- WDS Forms helpers ----------

function wdsf_values(): array
{
    $json = str_contains($_SERVER['CONTENT_TYPE'] ?? '', 'application/json');
    $input = $json ? json_decode(file_get_contents('php://input') ?: 'null', true) : ($_SERVER['REQUEST_METHOD'] === 'GET' ? $_GET : $_POST);
    $input = is_array($input) ? $input : [];
    $values = [];
    foreach (FIELDS as $f) {
        $name = $f['name'];
        $raw = $input[$name] ?? null; // PHP turns name[] into an array
        if ($f['type'] === 'checkbox' || $f['type'] === 'switch') {
            $values[$name] = $raw === true || in_array($raw, ['true', '1', 'on'], true);
        } elseif ($f['type'] === 'file' && !$json) {
            $values[$name] = wdsf_files($name);
        } elseif (!empty($f['multiple'])) {
            $values[$name] = array_values(array_filter(array_map('strval', array_filter((array) ($raw ?? []), 'is_scalar')), fn ($v) => $v !== ''));
        } else {
            $values[$name] = is_scalar($raw) ? trim((string) $raw) : '';
        }
    }
    return $values;
}

function wdsf_files(string $name): array
{
    $f = $_FILES[$name] ?? null;
    if (!$f) {
        return [];
    }
    $files = [];
    foreach ((array) $f['name'] as $i => $fileName) {
        $error = is_array($f['error']) ? $f['error'][$i] : $f['error'];
        if ($error === UPLOAD_ERR_NO_FILE) {
            continue;
        }
        $files[] = [
            'name' => (string) $fileName,
            'type' => (string) (is_array($f['type']) ? $f['type'][$i] : $f['type']),
            'size' => $error === UPLOAD_ERR_OK ? (int) (is_array($f['size']) ? $f['size'][$i] : $f['size']) : PHP_INT_MAX,
            'tmp_name' => (string) (is_array($f['tmp_name']) ? $f['tmp_name'][$i] : $f['tmp_name']),
            'error' => $error,
        ];
    }
    return $files;
}

function wdsf_empty(mixed $value): bool
{
    return $value === null || $value === '' || $value === false || $value === [];
}

function wdsf_fill(string $message, array $values): string
{
    foreach ($values as $key => $value) {
        $message = str_replace('{' . $key . '}', (string) $value, $message);
    }
    return $message;
}

function wdsf_check(array $f, mixed $value): ?string
{
    $m = MESSAGES;
    $type = $f['type'];
    if ($type === 'hidden') {
        return null;
    }
    if (wdsf_empty($value)) {
        if (empty($f['required'])) {
            return null;
        }
        return match ($type) {
            'checkbox', 'switch' => $m['requiredCheck'],
            'radio', 'checkboxes', 'select' => $m['requiredChoice'],
            'file' => $m['requiredFile'],
            default => $m['required'],
        };
    }
    if ($type === 'file') {
        foreach ($value as $file) {
            if (!is_array($file)) {
                continue;
            }
            if (!empty($f['maxSize']) && $file['size'] > $f['maxSize'] * 1024 * 1024) {
                return wdsf_fill($m['fileSize'], ['max' => $f['maxSize']]);
            }
            if (!empty($f['accept']) && !wdsf_accepts($file, $f['accept'])) {
                return $m['fileType'];
            }
        }
        return null;
    }
    if (isset($f['options'])) { // a choice must be one of the options
        foreach ((array) $value as $choice) {
            if (!in_array((string) $choice, $f['options'], true)) {
                return $m['requiredChoice'];
            }
        }
        return null;
    }
    if (is_bool($value) || is_array($value)) {
        return null;
    }
    $text = (string) $value;
    switch ($type) {
        case 'email':
            if (!preg_match('/^[^\s@]+@[^\s@.]+(\.[^\s@.]+)+$/u', $text)) {
                return $m['email'];
            }
            break;
        case 'url':
            if (!preg_match('~^https?://~i', $text) || filter_var($text, FILTER_VALIDATE_URL) === false) {
                return $m['url'];
            }
            break;
        case 'tel':
            if (!preg_match('/^\+?[0-9\s().-]{5,20}$/', $text)) {
                return $m['tel'];
            }
            break;
        case 'number':
        case 'range':
            if (!is_numeric($text)) {
                return $m['number'];
            }
            if (isset($f['min']) && (float) $text < (float) $f['min']) {
                return wdsf_fill($m['min'], ['min' => $f['min']]);
            }
            if (isset($f['max']) && (float) $text > (float) $f['max']) {
                return wdsf_fill($m['max'], ['max' => $f['max']]);
            }
            break;
        case 'date':
        case 'time':
            if (isset($f['min']) && strcmp($text, $f['min']) < 0) {
                return wdsf_fill($m['minDate'], ['min' => $f['min']]);
            }
            if (isset($f['max']) && strcmp($text, $f['max']) > 0) {
                return wdsf_fill($m['maxDate'], ['max' => $f['max']]);
            }
            break;
    }
    $length = mb_strlen($text);
    if (!empty($f['minLength']) && $length < $f['minLength']) {
        return wdsf_fill($m['minLength'], ['min' => $f['minLength']]);
    }
    if (!empty($f['maxLength']) && $length > $f['maxLength']) {
        return wdsf_fill($m['maxLength'], ['max' => $f['maxLength']]);
    }
    if (!empty($f['pattern'])) {
        $ok = @preg_match('~^(?:' . str_replace('~', '\~', $f['pattern']) . ')$~u', $text);
        if ($ok === 0) { // false means the pattern itself is broken: it is ignored
            return $f['patternMessage'] ?? $m['pattern'];
        }
    }
    return null;
}

function wdsf_accepts(array $file, string $accept): bool
{
    $name = strtolower($file['name']);
    $type = strtolower($file['type']);
    foreach (explode(',', $accept) as $rule) {
        $rule = strtolower(trim($rule));
        if ($rule === '') {
            continue;
        }
        if ($rule[0] === '.' ? str_ends_with($name, $rule) : (str_ends_with($rule, '/*') ? str_starts_with($type, substr($rule, 0, -1)) : $type === $rule)) {
            return true;
        }
    }
    return false;
}

function wdsf_rule(array $rule, mixed $value): bool
{
    $expected = (string) ($rule['value'] ?? '');
    $list = is_array($value) ? array_map(fn ($v) => is_array($v) ? (string) $v['name'] : (string) $v, $value) : null;
    $text = match (true) {
        $value === null => '',
        $list !== null => implode(',', $list),
        is_bool($value) => $value ? 'true' : 'false',
        default => (string) $value,
    };
    $checked = $value === true || ($list !== null && count($list) > 0);
    return match ($rule['op']) {
        'eq' => $list !== null ? in_array($expected, $list, true) : $text === $expected,
        'neq' => $list !== null ? !in_array($expected, $list, true) : $text !== $expected,
        'contains' => $list !== null ? in_array($expected, $list, true) : str_contains(mb_strtolower($text), mb_strtolower($expected)),
        'notContains' => $list !== null ? !in_array($expected, $list, true) : !str_contains(mb_strtolower($text), mb_strtolower($expected)),
        'empty' => wdsf_empty($value),
        'notEmpty' => !wdsf_empty($value),
        'gt' => is_numeric($text) && is_numeric($expected) && (float) $text > (float) $expected,
        'lt' => is_numeric($text) && is_numeric($expected) && (float) $text < (float) $expected,
        'checked' => $checked,
        'unchecked' => !$checked,
        default => true,
    };
}

function wdsf_shown(array $f, array $seen): bool
{
    $rules = $f['showIf']['rules'] ?? [];
    if (!$rules) {
        return true;
    }
    $results = array_map(fn ($rule) => wdsf_rule($rule, $seen[$rule['field']] ?? null), $rules);
    return ($f['showIf']['logic'] ?? 'all') === 'any' ? in_array(true, $results, true) : !in_array(false, $results, true);
}

/** The names of the fields shown for these answers (conditions can depend on each other). */
function wdsf_visible(array $values): array
{
    $visible = array_column(FIELDS, 'name');
    for ($pass = 0; $pass < 5; $pass++) {
        $seen = array_intersect_key($values, array_flip($visible));
        $next = array_column(array_filter(FIELDS, fn ($f) => wdsf_shown($f, $seen)), 'name');
        if ($next === $visible) {
            break;
        }
        $visible = $next;
    }
    return $visible;
}

function wdsf_validate(array $values, array $visible): array
{
    $errors = [];
    foreach (FIELDS as $f) {
        if (!in_array($f['name'], $visible, true)) {
            continue;
        }
        $error = wdsf_check($f, $values[$f['name']] ?? null);
        if ($error !== null) {
            $errors[$f['name']] = $error;
        }
    }
    return $errors;
}

function wdsf_label(string $name): string
{
    foreach (FIELDS as $f) {
        if ($f['name'] === $name) {
            return $f['label'];
        }
    }
    return $name;
}

function wdsf_summary(array $values): string
{
    $lines = [];
    foreach ($values as $name => $value) {
        $text = match (true) {
            is_bool($value) => $value ? 'yes' : 'no',
            is_array($value) => implode(', ', array_map(fn ($v) => is_array($v) ? $v['name'] : (string) $v, $value)),
            default => (string) $value,
        };
        $lines[] = wdsf_label($name) . ': ' . $text;
    }
    return implode("\n", $lines);
}

function wdsf_page(string $body): void
{
    $back = isset($_SERVER['HTTP_REFERER']) ? '<p><a href="' . htmlspecialchars($_SERVER['HTTP_REFERER']) . '">' . htmlspecialchars(MESSAGES['back']) . '</a></p>' : '';
    header('Content-Type: text/html; charset=utf-8');
    echo '<!DOCTYPE html><html lang="en"><head><meta charset="utf-8"><meta name="viewport" content="width=device-width, initial-scale=1"><title>Form</title></head>';
    echo '<body style="font-family: system-ui, sans-serif; max-width: 640px; margin: 40px auto; padding: 0 20px">' . $body . $back . '</body></html>';
}

Before you go live, add your own protection where your site needs it: a login check, an anti-forgery token, a rate limit or a CAPTCHA against spam.

HTML without JavaScript

Get code, HTML only gives the form as markup for the selected theme; tick Whole HTML page for a page with the framework's CSS linked. The browser checks required, min, max and pattern itself, and the form is sent as a normal post to its address. Conditional fields and steps need the embed code: in plain HTML all fields are shown and page breaks become headings.

Themes

Pick the theme in the builder's menu; the preview and all the code follow it.

ThemeNeeds on the page
Bootstrap 5Bootstrap 5 CSS (form-control, form-select, form-check, row g-3)
Bootstrap 6Bootstrap 6 CSS (form-field, check, radio, switch, md:col-6)
Tailwind CSSTailwind CSS v4: the browser build, or your own build with the package as a source (below)
PlainThe small wds-forms.min.css stylesheet, linked in the embed code

A Tailwind build only makes the classes it finds in your files. Install wds-forms from npm and add it as a source:

/* app.css (Tailwind CSS v4) */
@import "tailwindcss";
@source "../node_modules/wds-forms/dist";

Field types

TypeFieldSent as
Text, Email, Phone, Password, WebsiteSingle-line inputs with format checksText
Number, SliderNumber input and slider with its value shown, with lowest and highestNumber
Text areaMulti-line text with a length limitText
DropdownSingle or multiple choiceText or list
Radio buttons, CheckboxesOne or several options, stacked or side by sideText or list
Checkbox, SwitchA single yes/no, for example accepting the privacy policytrue or nothing
Date, TimeThe browser's pickers, with earliest and latestISO text
File uploadAllowed types, size limit, one or more filesFiles
HiddenA fixed value such as the page or campaignText
Heading, Paragraph, DividerText and lines between fields–
Page breakStarts a new step–

Conditional fields

Any field, heading or paragraph can be shown only when other answers match. Select it in the builder and turn on Show this field only when… in the Logic settings. The rules: is, is not, contains, does not contain, is empty, is not empty, greater than, less than, is checked and is not checked, combined with all or any. For checkboxes and multiple dropdowns, is means "one of the chosen options is". Hidden fields are not checked and not sent, and the server code skips them too.

Multi-step forms

Drag a Page break into the form and everything after it becomes the next step; its label is the step title. The form shows a progress bar, Step 1 of 3 and Back and Next buttons, checks each step before moving on and skips steps whose fields are all hidden.

Validation

Fields are checked when they lose focus after a change, before Next and before sending. Messages appear under the field, the field gets aria-invalid (and is-invalid for Bootstrap) and the focus moves to the first error. The server code checks the same rules again, because a browser check alone can be skipped.

The WDS Forms script

The forms run with WDS Forms, a free and open source script (MIT license, v1.0.0, about 11 KB gzipped, no dependencies). The embed code loads it from jsDelivr; you can also install it from npm or host the file yourself. Load a form JSON you saved from the builder:

<!-- Your page already loads Bootstrap 5 -->
<div id="contact"></div>

<script src="https://cdn.jsdelivr.net/npm/wds-forms@1/dist/wds-forms.min.js"></script>
<script>
  fetch('/forms/contact.json')
    .then((res) => res.json())
    .then((schema) => WDSForms.render('#contact', schema, { theme: 'bootstrap5' }));
</script>
npm install wds-forms
import { render } from 'wds-forms';
import 'wds-forms/style.css'; // only for the plain theme

const form = render('#contact', schema, { theme: 'tailwind' });
form.on('success', ({ values }) => console.log(values));

Listen to the form's events, for example to count a conversion:

// Every form sends events that bubble up the page
document.addEventListener('wdsf:success', (e) => {
  console.log('Sent', e.detail.values); // for example: count a conversion or go to a thank-you page
});

// The form object of an embedded form
const form = WDSForms.get(document.querySelector('[data-wds-form]'));
form.setValues({ topic: 'support' });

Send an anti-forgery token, or handle the answers yourself:

WDSForms.render('#contact', schema, {
  theme: 'bootstrap5',
  // sent with every request to settings.action, for example an anti-forgery token
  headers: { 'RequestVerificationToken': token },
  // or send the answers yourself
  onSubmit: async (values, form) => {
    const res = await fetch('/api/contact', {
      method: 'POST',
      headers: { 'Content-Type': 'application/json' },
      body: JSON.stringify(values)
    });
    if (res.status === 422) {
      form.setErrors((await res.json()).errors);
      return false;
    }
    return res.ok; // false shows the error message
  }
});

Show the messages in your language:

WDSForms.render('#contact', schema, {
  theme: 'bootstrap5',
  messages: {
    required: 'Bu alan zorunludur.',
    email: 'Geçerli bir e-posta adresi girin.',
    minLength: 'En az {min} karakter girin.',
    step: 'Adım {n} / {total}',
    success: 'Teşekkürler! Formunuz gönderildi.'
  }
});

In Node.js the package checks answers with the form JSON itself, the same way as the browser:

// Node.js: check the answers with the form JSON itself
import { validateValues } from 'wds-forms';
import schema from './forms/contact.json' with { type: 'json' };

app.post('/contact', express.json(), (req, res) => {
  const errors = validateValues(schema, req.body);
  if (Object.keys(errors).length) return res.status(422).json({ errors });
  // save or send the message …
  res.json({ ok: true });
});

The JSON format

A form is a list of fields plus a few settings. The builder's JSON tab shows it, applies your edits and downloads it, so you can keep your forms and load them again later.

{
  "title": "Contact us",
  "fields": [
    { "id": "f1", "type": "text", "name": "name", "label": "Name", "required": true, "width": 6 },
    { "id": "f2", "type": "email", "name": "email", "label": "Email", "required": true, "width": 6 },
    {
      "id": "f3", "type": "select", "name": "topic", "label": "Topic", "placeholder": "Choose…",
      "options": [{ "label": "Sales", "value": "sales" }, { "label": "Support", "value": "support" }]
    },
    {
      "id": "f4", "type": "text", "name": "order", "label": "Order number",
      "showIf": { "rules": [{ "field": "topic", "op": "eq", "value": "support" }] }
    },
    { "id": "f5", "type": "textarea", "name": "message", "label": "Message", "rows": 5, "maxLength": 2000 }
  ],
  "settings": { "action": "/contact", "submitText": "Send", "successMessage": "Thanks, we will reply soon." }
}

Conditions and page breaks in the JSON:

{
  "id": "f5", "type": "text", "name": "company", "label": "Company name", "required": true,
  "showIf": {
    "logic": "any",
    "rules": [
      { "field": "customer_type", "op": "eq", "value": "business" },
      { "field": "invoice", "op": "checked" }
    ]
  }
}
{ "id": "p1", "type": "page", "label": "Your details" },
{ "id": "f1", "type": "text", "name": "name", "label": "Name", "required": true },
{ "id": "p2", "type": "page", "label": "Delivery" },
{ "id": "f2", "type": "text", "name": "address", "label": "Address", "required": true }

Field settings: id, type, name (the key the answer is sent under), label, placeholder, help, value (default), required, disabled, readonly, options, multiple, inline, min, max, step, minLength, maxLength, pattern, patternMessage, accept, maxSize (MB), rows, width (3, 4, 6, 8, 9 or 12 of 12), text, level, showIf, className and autocomplete.

Form settings: action, method (post or get), submitAs (form or json), submitText, resetText, nextText, prevText, successMessage, errorMessage, showProgress and buttonAlign (start, center or end).

API

// Forms in the page: <div data-wds-form data-theme="…"><script type="application/json">…</script></div>
WDSForms.renderAll();        // runs by itself when the page has loaded; call it again for forms added later
WDSForms.get(element);       // the form object of an embedded form

// A form from JSON
const form = WDSForms.render('#contact', schema, { theme, messages, onSubmit, headers, values, resetOnSuccess });
form.getValues();            // { name: 'Ann', topic: 'sales', … } (hidden conditional fields are left out)
form.setValues({ name: 'Ann' });
form.validate();             // true or false, shows the messages
form.getErrors(); form.setErrors({ email: 'Already registered.' });
form.next(); form.prev(); form.goTo(0); form.step; form.stepCount;
await form.submit();         // true when sent
form.reset();
form.on('change' | 'step' | 'submit' | 'success' | 'error' | 'invalid' | 'reset', (detail) => {});
form.destroy();

// Helpers
WDSForms.toHTML(schema, { theme, standalone }); // static HTML
WDSForms.validate(schema, values);              // { email: 'Enter a valid email address.' }, also in Node
WDSForms.version;

Security and Content Security Policy

Labels, options and texts from the JSON are escaped before they are shown. The embed code needs no inline script and no unsafe-eval: allow https://cdn.jsdelivr.net in script-src (and in style-src for the framework CSS from the CDN), or host both files yourself. The form writes no style attributes except the width of the progress bar, which it sets from JavaScript. Always check the answers on the server too; the server code does.

FAQ

Is the form builder free?

Yes. Building forms and copying their code is free, without an account or a limit. The forms and the code you copy are yours: use them on any site, also for clients and in commercial projects.

Do you store my forms or the answers?

No. The builder runs in your browser and nothing you build or type is sent to WebDevSnippets. The answers of your visitors go straight to your own server, to the address you set.

How do I add the form to my website?

Open Get code, copy the Embed code and paste it into your page where the form should appear. Then put the server code for your language at the address the form is sent to. That is all: the form checks the answers, shows conditional fields and steps, and sends without leaving the page.

Which server languages are there?

PHP, Node.js (Express), ASP.NET Core (C#) and Python (Flask). The code is made for your form: it checks every field again with the same rules as the browser, skips fields hidden by their conditions, accepts file uploads and replies the way the form expects. Where it says so, add your own code to save or email the answers.

Can I use the form without JavaScript?

Yes. Get code, HTML only gives static HTML with the browser's own checks (required, min, max, pattern). It is sent as a normal post, and the server code answers it with a simple page. Conditional fields and steps need the embed code.

Which CSS frameworks are supported?

Bootstrap 5, Bootstrap 6 and Tailwind CSS, plus a plain theme with its own small stylesheet for sites without a framework. Switch the theme in the builder and the preview and the code change with it.

Can fields show or hide based on other answers?

Yes. Select a field and turn on "Show this field only when…" in its Logic settings: is, is not, contains, is empty, greater than, is checked and more, combined with all or any. Hidden fields are not checked and not sent, in the browser and in the server code.

Does it make multi-step forms?

Yes. Drag a Page break into the form and it becomes a wizard with a progress bar and Back and Next buttons. Each step is checked before the next one opens.

What runs the form on my site?

WDS Forms, a small open source script (MIT license, about 11 KB gzipped) loaded from the jsDelivr CDN. You can also install it from npm as wds-forms or host the file yourself. It has no dependencies and works with any back end.

Can I translate the messages?

Yes. The labels, help texts and buttons are your own text from the builder, in any language. For the built-in messages such as "This field is required.", render the form with the messages option, and change the same texts in the MESSAGES list of the server code.

Is the form accessible?

Labels are linked to their inputs, groups use fieldset and legend, errors set aria-invalid and are linked with aria-describedby, and the focus moves to the first field with an error. The builder works with the keyboard too.

License

The form builder on this page is free to use. The forms you build and the code you copy from it are yours, for any project, free or paid. The script that runs the forms, WDS Forms, is open source under the MIT license. Need a rich text editor too? Try WDS Editor, free and MIT as well.