Forms
Any HTML form on a Lobsite site can collect messages: point its action at /_lobsite/forms/<name> and deploy. There's no backend to write, no script to add and no key to paste. Submissions land on the Submissions page of your dashboard and in your email.
<form action="/_lobsite/forms/contact" method="POST">
<input name="email" type="email" required>
<textarea name="message" required></textarea>
<button>Send</button>
</form>
How forms work
- The action names the form.
/_lobsite/forms/contactis the formcontact. Names are lowercase letters, digits,-and_. Use one name per purpose (contact,newsletter,quote); several pages can share one form. - Forms are found at deploy time. The deploy reads the HTML files and records each form that posts to
/_lobsite/forms/. The form has to be in an HTML file in the deployed folder: a form that only exists after JavaScript renders it isn't found (see Frameworks). - Fields are stored as you name them. Every field with a
nameis kept, as text. A field namedemailis used as the Reply-To of the notification email and as the title on the Submissions page. File uploads aren't supported. - Spam protection is added for you. When the page is served, a hidden honeypot field and a signed timestamp are added to the form. Submissions that fill the honeypot or come back within 2 seconds are kept apart as spam, and too many in a row from one visitor are refused.
- After sending, the visitor sees a thank-you page with a link back, or the page you set with
redirect. - Forms work on production URLs. Preview deploys don't accept submissions, and a site deployed without an account accepts them once it's claimed.
Form types
Each form is one of four types, which decides how the dashboard shows what it collects:
- contact: messages to read and reply to. The Submissions page shows each message.
- waitlist: signups, counted above the table and kept for as long as the form exists.
- survey: answers summed up per question on the form's Results page. See Survey.
- quiz: answers scored, with each person's score on the Results page. See Quiz.
Say which one with data-lobsite-type on the <form>:
<form action="/_lobsite/forms/feedback" method="POST" data-lobsite-type="survey">
Without it, Lobsite picks the type when you deploy, in this order:
- A questions block makes the form a quiz when any question has an answer, otherwise a survey.
- A form named
waitlist,newsletter,signup,subscribe,early-access,betaornotifyis a waitlist;quiz,test,examortriviais a quiz;survey,feedback,poll,questionnaire,npsorrsvpis a survey. - A form with three or more choice questions (radio groups, checkbox groups or selects) and no message box is a survey.
- A form whose visitors fill in an email and at most a name is a waitlist. Hidden fields, fields starting with
_and a single checkbox (a consent box) don't count. - Every other form is a contact form.
type in lobsite.toml overrides all of these:
[forms.launch]
type = "waitlist" # contact, waitlist, survey or quiz
Waitlist signups are kept for as long as the form exists; other submissions are kept for the plan's retention period (see Limits).
Contact form
A complete page with a name, an email and a message. The labels and the autocomplete values make it easy to fill in; the required attributes stop an empty submission before it's sent.
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Contact</title>
</head>
<body>
<h1>Get in touch</h1>
<form action="/_lobsite/forms/contact" method="POST">
<label>Name
<input name="name" autocomplete="name" required>
</label>
<label>Email
<input name="email" type="email" autocomplete="email" required>
</label>
<label>Message
<textarea name="message" rows="5" required></textarea>
</label>
<button type="submit">Send</button>
</form>
</body>
</html>
To check the same fields on the server and send visitors to your own thank-you page, add the form to lobsite.toml and create thanks.html:
[forms.contact]
required = ["name", "email", "message"]
types = { email = "email" }
redirect = "/thanks"
Waitlist
Before launch, an email field is all you need. The form's name makes it a waitlist; setting type says so outright. Signups are counted on the Submissions page and kept for as long as the form exists.
<form action="/_lobsite/forms/waitlist" method="POST">
<label for="wl-email">Get early access</label>
<input id="wl-email" name="email" type="email" autocomplete="email" placeholder="you@example.com" required>
<button>Join the waitlist</button>
</form>
[forms.waitlist]
type = "waitlist"
required = ["email"]
types = { email = "email" }
Newsletter signup
One field is enough. A second form on the same site gets its own name, so signups and messages stay apart on the Submissions page and in exports. A form with just an email field (and at most a name) is a waitlist: see Form types.
<form action="/_lobsite/forms/newsletter" method="POST">
<label for="nl-email">Get updates by email</label>
<input id="nl-email" name="email" type="email" autocomplete="email" required>
<input type="hidden" name="_redirect" value="/subscribed">
<button>Subscribe</button>
</form>
_redirect is a hidden field that picks the page shown after sending. It must be a path or a URL on the same site; redirect in lobsite.toml takes precedence.
Quote request
Selects, radio buttons and checkboxes work as usual. Checkboxes with the same name are stored as one comma-separated value.
<form action="/_lobsite/forms/quote" method="POST">
<input name="name" autocomplete="name" required>
<input name="email" type="email" autocomplete="email" required>
<input name="phone" type="tel" autocomplete="tel">
<select name="budget">
<option>Under $1,000</option>
<option>$1,000 to $5,000</option>
<option>Over $5,000</option>
</select>
<fieldset>
<legend>Services</legend>
<label><input type="checkbox" name="services" value="Design"> Design</label>
<label><input type="checkbox" name="services" value="Development"> Development</label>
<label><input type="checkbox" name="services" value="Hosting"> Hosting</label>
</fieldset>
<textarea name="details" required></textarea>
<button>Request a quote</button>
</form>
Survey
A survey is a form of questions. Put each group of radio buttons or checkboxes in a <fieldset> with the question as its <legend>; for other fields, the <label> is the question. The Results page sums up the answers to each question, using the text the page shows.
<form action="/_lobsite/forms/feedback" method="POST" data-lobsite-type="survey" data-lobsite-one-response>
<fieldset>
<legend>How did you hear about us?</legend>
<label><input type="radio" name="source" value="Search" required> Search</label>
<label><input type="radio" name="source" value="A friend"> A friend</label>
<label><input type="radio" name="source" value="Social media"> Social media</label>
</fieldset>
<fieldset>
<legend>How likely are you to recommend us?</legend>
<label><input type="radio" name="score" value="0"> 0</label>
<!-- … 1 to 9 … -->
<label><input type="radio" name="score" value="10"> 10</label>
</fieldset>
<label>Anything we could do better? <textarea name="improve"></textarea></label>
<button>Send</button>
</form>
data-lobsite-one-responsetakes one response per browser: a second one is turned away with{"ok": false, "error": "already_answered"}. It's a convenience, not security. It can also be switched in the form's settings.- A field inside an element with
hidden,data-show-ifordata-lobsite-optionalis a question that may not be shown, so Results counts it as "not shown" rather than "skipped". data-lobsite-label="…"on a field sets its question when the label text isn't right.
Quiz
A quiz is a survey that Lobsite scores. Its questions and right answers go in a questions block, a JSON script next to the form whose data-lobsite-form is the form's name. Each question's id is the name of its field:
<script type="application/json" data-lobsite-form="practice">
{
"title": "The water cycle",
"questions": [
{ "id": "q1", "q": "What is it called when water turns into vapour?", "options": ["Condensation", "Evaporation", "Precipitation"], "answer": 1 },
{ "id": "q2", "q": "Which of these store water?", "type": "multi", "options": ["Oceans", "Glaciers", "Sand"], "answer": [0, 1] },
{ "id": "q3", "q": "What falls from clouds as water?", "type": "text", "answer": "rain" }
]
}
</script>
<form id="practice" action="/_lobsite/forms/practice" method="POST" data-lobsite-type="quiz">
<label>Your name <input name="name" required></label>
<fieldset>
<legend>What is it called when water turns into vapour?</legend>
<label><input type="radio" name="q1" value="Condensation" required> Condensation</label>
<label><input type="radio" name="q1" value="Evaporation"> Evaporation</label>
<label><input type="radio" name="q1" value="Precipitation"> Precipitation</label>
</fieldset>
<!-- q2 as checkboxes named q2, q3 as a text field named q3 -->
<button>Check my answers</button>
</form>
answeris an option's index or text, a list of them for"type": "multi", or the text for"type": "text". Text answers are compared ignoring case and extra spaces. A field can send the option's text or its index.- Each response is scored when it arrives, and its score shows on the Results page and in webhooks. A
scorefield the page sends is kept but never used. - Answers in the page let the page show the score right away, worked out from the block, as Sending without leaving the page does for messages. Anyone who opens the page source can see them, which is fine for practice.
- Hidden answers: leave
answerout of the block, keepdata-lobsite-type="quiz", and set the right answers in the form's settings on the dashboard after deploying. Lobsite scores with them and never sends them to the page, so the page can only thank the student. Answers set in the dashboard win over the block's. data-lobsite-one-responsegives each browser one try, as for a survey.
Sending without leaving the page
To show a message in place instead of loading a new page, send the form with fetch. Build the body with new FormData(form) so the hidden spam fields go along, and ask for JSON with the Accept header:
<form id="contact" action="/_lobsite/forms/contact" method="POST">
<input name="email" type="email" required>
<textarea name="message" required></textarea>
<button>Send</button>
<p id="contact-status" role="status"></p>
</form>
<script>
const form = document.getElementById("contact");
const status = document.getElementById("contact-status");
form.addEventListener("submit", async (event) => {
event.preventDefault();
status.textContent = "Sending…";
const res = await fetch(form.action, {
method: "POST",
body: new FormData(form),
headers: { Accept: "application/json" },
});
const answer = await res.json();
if (answer.ok) {
form.reset();
status.textContent = "Thanks! We'll be in touch.";
} else {
status.textContent = answer.errors ? Object.entries(answer.errors).map(([field, why]) => `${field}: ${why}`).join(", ") : "Something went wrong. Please try again.";
}
});
</script>
The answer is {"ok": true}, or {"ok": false, "errors": {"email": "Required"}} for fields that didn't pass, or {"ok": false, "error": "rate_limited"} (also too_large, not_found, forms_off). Without the script, the same form still works as a plain form.
Frameworks
React, Vue, Svelte, Astro and the rest work when the form is in the built HTML, which is what prerendering and static export produce (Astro and Eleventy by default, Next.js with output: "export", SvelteKit with prerender, Nuxt with nuxt generate). Keep the action and method attributes on the <form> element itself.
In a single-page app, the form has to be in the built HTML and stay as served: a form that exists only in JavaScript isn't recorded and its submissions are refused, and a form the browser re-renders loses the spam fields, so its messages land in Spam.
// React: a plain form element, prerendered into the HTML.
export function Contact() {
return (
<form action="/_lobsite/forms/contact" method="POST">
<input name="email" type="email" required />
<textarea name="message" required />
<button>Send</button>
</form>
);
}
Settings
Each form can have a section in lobsite.toml. All keys are optional; the settings travel with the deploy.
[forms.contact]
type = "contact" # contact, waitlist, survey or quiz; inferred when left out
required = ["email", "message"] # fields that can't be empty
types = { email = "email", phone = "tel" } # text, email, number, url or tel
redirect = "/thanks" # the page shown after sending
notify = ["you@example.com"] # who gets an email for each message
webhook = "https://example.com/hooks/contact" # POSTs each submission as JSON
A submission that fails required or types isn't stored; the visitor sees what to fix and a link back. On the free plan, notify can only be your account email and webhook isn't available.
Reading submissions
- The Submissions page on your dashboard shows every form's submissions in one table. Search them, narrow them by site and by form type, and switch to spam to see what the checks caught. A submission is New until you open it.
- Each message is emailed to your account address, with Reply-To set to the sender.
lobsite forms lslists your forms;lobsite forms export contact --csvdownloads one form's submissions. Export CSV on the Submissions page downloads what the table shows.
On the free plan, forms run in limited mode: a monthly quota per site, notifications to your account email only, and no webhooks. Messages over the quota aren't lost: they're kept but hidden until you upgrade or the next month starts, up to four times the quota.
Surveys and quizzes email you their first response, then one summary a day of the previous day's responses (UTC), with a quiz's average score and hardest question. Choose an email for every response in the form's settings. The Standard plan adds webhooks, any verified notification address and no monthly cap. See Limits.