A CRM form can reach a site three ways. Pick one before building anything, because each one changes which address the visitor uses, what the page looks like, and where the form's emails send people.
| A. The platform form | B. A page tied to a form | C. A page of your own | |
|---|---|---|---|
| What it is | The built-in form, one question per screen, at /form?form=<name> | A site page with data.formName set. The form renders between the page's two screens. | Your own HTML and JS that posts to the form's endpoints through the site's /api |
| Needs Forms switched on in Site Features | Yes. Off, /form is a 404. | Yes. Off, the page shows as itself, with no form. | No |
| Looks | Fixed platform design | Fixed platform design inside your header and footer | Anything |
| Code gates, magic links, invitations | Built in: the gate screens, "Send me the link", invitation links | Built in, the same as A | You write each step (request the code, ask for it, show each refusal) |
| Emails' "Open the form" link | Opens it | Opens the platform form at /form or the Forms page, not this page | Still points at /form or the Forms page, never at your page (see the warning in way C) |
| Embed in another website | ?embed=true | ?embed=true | Not built in |
| Use when | A form should just work, a share link, invitations | A form that should sit inside the site's design at its own address | A custom design or flow, e.g. a multi-step registration wizard |
Default to A. Use B when the owner wants the form at its own address inside their page. Use C only when the design or flow can't be the platform form. A site built this way (PhaZZer's /registration) is a 7-step wizard of its own design that posts to a code-gated CRM form, with Forms switched off.
Related skills: Shared form from a collection builds the collection and the form. Registration that creates the customer adds a unique email and an automation that creates the account. How a site's addresses route covers features, pages and 404s. Page building: Build a website page. The API by hand: Collect form submissions.
Ask first
- Which form, and does it exist? Its name, or what it should ask. If it doesn't exist, build it first with Shared form from a collection.
- Who may fill it in? Anyone, anyone with a shared code, people who prove their email, invited people, or signed-in customers. This sets
authenticationType(see Who gets in). - Where on the site, and how should it look? The platform's own form (A), inside one of their pages (B), or a page of their own design (C). Which address? Never guess an address: it may already belong to a page or a feature.
- Is Forms switched on for the site? If not, may it be? Ways A and B need it, and switching it on changes what
/formshows. - Who is told of each answer? A staff address (
emailon the form), and whether the visitor gets a confirmation (they do, whenever they give an email).
How it works
The form record (crm_form)
The fields that change what a visitor sees on a site. Model: @jaclight/dbsdk models/crm/crm-form.d.ts. Behaviour: appengine src/crm/crm-form.service.ts and src/util/access-gate.ts.
| Field | What it does on the site |
|---|---|
name | The form's address: /form?form=<name>, /form/<name>, POST /client/forms/<name>/…. Lowercase letters, numbers, _ and -; unique. |
title / description | Shown above the questions and on the gate screens. Email subjects use title. |
collection | The collection whose records the answers become. Its schema is the questions. Empty: the form's own schema is the questions and each answer is a form_submission. See Where answers land. |
schema | The questions when there's no collection. JSON schema; the builder keeps page 1's fields at the root and later pages in schema.pages[i].properties. |
authenticationType | Who gets in: none, email, code, magic-link, password. The model's default is email, and Studio's too. See below. |
accessCode | The shared code for authenticationType: "code". Compared trimmed and case-insensitive. |
participants | [{ email, name, accessCode, role }]. When not empty, only these people get in, whatever the type. Each one's accessCode is their own key, carried in their invitation link. The engine adds invitedAt, inviteCount, submittedAt. |
status | closed, cancelled, expired or failed refuse readers and answers with 403 closed. new, sent, open (or none) are open. |
startDate / endDate | Before the start: 403 not-open-yet (with opensAt). After the end: 403 closed (with closedAt). |
permission | { read: [...], create: [...] }. Left out, the form is open. A read list without Guest gives 403 "This form is not available for public access"; a create list without Guest gives 403 "This form does not accept public submissions". Studio's Access tab "Public" switch writes these. |
submitMessage | The thank-you screen of the platform form (HTML is reduced to text). Before it: the page's data.thankYou, then the site's data.forms.thankYou, then "Thank you — that's everything." (base-app SchemaFormRoute.tsx 280). Way C shows its own. |
email | The staff address. Every answer sends it a "New submission: crm-form.service.ts 1504, notifyTeam 1539). |
invitationTemplate | The template for invitations and access emails. Empty: the built-in form-invitation. |
templates, emailTemplate, smsTemplate | Extra messages sent with each answer to the visitor's address (templates are template names; the other two are inline bodies). |
workflow | A workflow definition, by name, that each answer is handed to (crm-form.service.ts 1421). |
signing | A document to sign. Signing links (?sign=<token>) open their own signer view; not covered here. |
The model describes email as "where a submission notification is sent when the submitter did not supply an address". The code sends the team email for every answer, whatever the visitor gave. Tested: a form with email: "team@test.local" sent both the visitor's confirmation and "New submission: Skilltest File" to the team address.
Who gets in (authenticationType)
One setting decides who sees the questions. It's checked when the form is read and when answers are sent, so a page can't skip it.
authenticationType | What the visitor does | What the server checks | Refusals |
|---|---|---|---|
none | Nothing. The questions open. | Nothing. | — |
email | Types an address before the questions (platform form), or sends one. | Only that an address is there. It's not verified: any address is accepted. | 401 email-required |
code with an accessCode | Types the shared code, or opens a link with ?code=. | The code, trimmed, ignoring case. A participant's own code also works. | 401 code-required; 403 code-wrong |
code with participants and no accessCode | Opens their own invitation link (?code=<their code>). | The code must be a participant's. | 403 invitation-required (no code); 403 not-a-participant (unknown code) |
code with no accessCode and no participants | Gives an email, is emailed a 6-digit code, types it in. | Treated as magic-link that emails a code (access-gate.ts 52, emailsCode 57). | 401 link-required, code-wrong, link-expired, already-submitted |
magic-link | Gives an email, is emailed a link (32-character token), opens it. | The token must match a pending submission for this form, under 72 hours old. The address is read off that record, never from the request. | Same as above |
password | Signs in as a customer first. | A signed-in customer (and on the list, if there is one). | 401 signin-required |
Records saved with the old accessMode of code or participants and a type of none or email are read as code (access-gate.ts 47–54).
codemeans two different things. With anaccessCodeor participants, it's a code you hand out. With neither, the server emails each visitor their own 6-digit code. That second one is what a registration page wants. A form withcodeand nothing else set never answersmisconfigured.emailproves nothing. Use the emailed code ormagic-linkwhen the address must be real.- A wrong shared code is 403, not 401. Tested:
code-wrongon acodeform came back 403;code-wrongon an emailed-code form came back 401. Readreason, not the status.
Endpoints
All are public: no admin token. From a site page, call them as /api/<path> (see The site's /api). Directly they need the orgid header.
| Call | Body / query | Answer |
|---|---|---|
GET /client/forms/<name> (also GET /crm/form/<name>) | ?code=, ?email=, ?token=, ?sign= | { form: { sk, data: { name, title, description, submitMessage, authenticationType, status, startDate, endDate, schema } }, collection, schema, authenticationType, authentication: { required, type, satisfied }, submitter, participant, session, displayName, logo, lookupOptions }. The form's notify address, participants and author are left out (toPublicReply 118). |
POST /client/forms/<name>/access (also /crm/form/<name>/access) | { "email": "…" } | { "sent": true, "email": "<lowercased>", "via": "code" | "magic-link", "session": "<pending submission sk>" }. Makes a pending form_submission and emails the code or link. Only for emailed-code and magic-link forms; any other gives 400 "This form does not send links or codes." A form with participants only sends to them (403 not-a-participant). |
POST /client/forms/<name>/submit | Answers as the body. Query: ?token=, ?code=, ?email= | The saved record, or true when it completes a pending submission (inline magic-link form). This is what the platform form posts to. |
POST /crm/form/submit/<name> and /crm/form/submit/<name>/<email> | Answers as the body. Query: ?token=, ?code= | The saved record. The visitor's email is the path segment, not ?email=. |
The code or token can be in the body (accessCode, token), the query (?code=, ?token=) or a header (x-form-code, x-form-token). It's removed before the answers are checked and never stored with them (crm-form.service.ts 1110–1119). Through the site's /api, only the body and query reach the engine.
?email= is ignored by /crm/form/submit/<name>. That route reads the email from the path. Tested on an email form: POST /crm/form/submit/<name>?email=q@test.local gave 401 email-required, while /client/forms/<name>/submit?email=q@test.local and /crm/form/submit/<name>/p@test.local let the visitor in. For an emailed-code form it doesn't matter, because the address comes from the code's own record. Put the email in the body too.
Refusal reasons
| Status | reason | When | What the page should do |
|---|---|---|---|
| 400 | — | "Form data is required" (empty body); "Please fill in Your name, Email." (missing required, by field title); "Topic: must be equal to one of the allowed values" | Show the message; it names the field. |
| 400 | — | "A valid email address is required" (access request) | Ask for a full address. |
| 401 | email-required | email form, no address | Ask for one. |
| 401 | code-required | code form, no code | Ask for the code. |
| 403 | code-wrong | code form, wrong shared code | "That code isn't right." |
| 401 | link-required | emailed-code or magic-link form, nothing sent | Ask for the email and request a code. |
| 401 | code-wrong | emailed-code or magic-link form, unknown code or token | "That code isn't right." Offer a new one. |
| 401 | link-expired | the code or link is over 72 hours old | Offer a new one. |
| 401 | already-submitted | the link already completed its submission (inline magic-link forms only) | Say it's been sent. |
| 403 | email-not-verified | the answers' email differs from the one the code was sent to | Send the verified email. |
| 403 | invitation-required / not-a-participant | a participants form, opened without their link | "Open it from the link you were sent." |
| 401 | signin-required | password form, not signed in | Send them to /login?redirect=…. |
| 403 | closed / not-open-yet | status or the dates | Say so; nothing to fix. |
| 403 | not-published | the org reviews forms before publishing and this one isn't approved | Publish it in Studio. |
| 403 | — | "This form is not available for public access" / "does not accept public submissions" | Fix permission on the form. |
| 404 | — | "No form or collection found with name | Check the name. |
| 409 | duplicate (with field) | a unique field already has this value in the collection | "An application from this email already exists." |
Where answers land
| The form | The answer is saved as | Marked | Notes |
|---|---|---|---|
No collection | a form_submission: { formId, values: {…answers}, status: "new", authentication: { method, status: "used", email, admittedBy, verified, submittedAt, client } } | data.formId = the form's sk | An inline magic-link answer completes the pending row the link was made for, so the proof and the answers are one record. |
With collection | a record of that collection, the answers as its fields, plus data.authentication: { admittedBy } | owner = { datatype: "crm_form", id: "<form name>" } | The collection's unique fields and schema apply. The pending form_submission from the code stays pending. |
admittedBy says which door was used: open, email, form-code, participant-code, link-session, signed-in, staff.
Tested. A participant's answer is filed under the participant's own address, whatever email the body carried, and the form's participants[i].submittedAt is set. A collection-bound form saves records even when the collection's own permission.create is ["User"] only: the form's permission decides, not the collection's.
Don't put Guest in the bound collection's permission. A collection with Guest in create (or read) is a public form in its own right, under its own name. It skips the CRM form's code. Tested: with Guest added to the test collection, /form?collection=<collection> opened its questions and POST /api/client/forms/<collection>/submit saved a record with no code, admittedBy: "open" and no owner, so an automation filtered on owner.id never saw it. With create: ["User"], the same call gave 403 "This collection is not shared publicly". The bound form needs nothing on the collection.
To act on each answer: for a form with no collection, trigger form_submitted. For one with a collection, trigger database_change on the collection with whereField: "owner.id", whereValue: "<form name>". See Registration that creates the customer step 3. Every answer also raises crm.form.submitted, which AI employees listening to forms hear (crm-form.service.ts 1410).
The emails
| Sent when | To | Template | Link in it | |
|---|---|---|---|---|
| Access code or link | POST …/access | the address given | invitationTemplate, else form-invitation (variant: "code" shows the 6-digit code) | Open the form → <forms page>?form=<name>&token=<code or token> (sendFormAccess, crm-form.service.ts 454–460) |
| Invitation | Studio's Send invitation, POST /crm/form/<name>/invite (staff) | each participant, or those in emails | the same | Open the form → <forms page>?form=<name>&code=<their code> (inviteParticipants 521–549). A resend is marked as a reminder and keeps their code. |
| Confirmation | each answer, if the visitor gave an address (the door's email, the form's email question, or email in the body) | the visitor | form-submission, plus templates, emailTemplate, smsTemplate | none |
| Team alert | each answer, when the form has email | that address only | built inline: "New submission: | none |
<forms page> is featurePageUrl(orgId, "forms") (appengine site.service.ts 1498–1515), read from the org's default site (data.isDefault, else the oldest site):
- a
formsrow that is on →https://<site host>/<row.page>; - a bare
"forms"in the list →https://<site host>/<site.data.forms.page or "form">; - Forms off, or no row →
null, and the emails fall back to<site origin>/form.
GET /site/base-url?feature=forms gives the same answer, or { "url": null, "reason": "Enable Forms in Site Features on your default site, then refresh this link." } when it's off. Studio's form Setup tab builds its share link from it: <that url>?form=<name>.
The engine's emails always link to the platform form, never to a page of your own. Tested with the site's Forms off: the code email for the test form linked to http://<site>/form?form=skilltest-form-otp&token=363946, and /form on that site is a 404. With Forms on, the same link opens the platform form with the code already applied, and the visitor can answer there instead of on your page. For way C, tell the person their visitors get an "Open the form" button that 404s (Forms off) or opens a different form (Forms on). The code itself is printed in the email too, which is what a way C page asks for. To change the button, give the form an invitationTemplate of its own whose text doesn't link.
Steps
1. CRM Forms: the form
Find the form: repo_find on crm_form with { "data.name": "<name>" }, then repo_find_one for the whole record. If it doesn't exist, make it with Shared form from a collection (with a collection) or repo_create on crm_form (inline schema). A minimal working record:
{
"name": "contact",
"title": "Contact us",
"status": "open",
"authenticationType": "none",
"email": "office@example.com",
"submitMessage": "Thanks, we'll be in touch.",
"schema": {
"type": "object",
"required": ["name", "email"],
"properties": {
"name": { "type": "string", "title": "Your name" },
"email": { "type": "string", "format": "email", "title": "Email" },
"topic": { "type": "string", "title": "Topic", "enum": ["sales", "support"], "enumNames": ["Sales", "Support"] },
"message": { "type": "string", "maxLength": 500, "title": "Message" }
}
}
}A registration-style form, bound to a collection and emailing each visitor a code:
{ "name": "apply", "title": "Apply", "status": "open", "authenticationType": "code",
"collection": "applications", "email": "office@example.com", "submitMessage": "Application received" }Set authenticationType from Ask first and the table above. Studio sets it on CRM → Forms (/crm-form) → the form → Access, which offers Nothing, Magic link, Access code, Username & password, and Email only (crm-form-detail.tsx 89–95).
Hands on: the form's name and its authenticationType.
Check: call_appengine GET /client/forms/<name> without anything: none answers 200 with the schema. The others answer the refusal in the table (e.g. 401 link-required for an emailed-code form). Open the form in Studio at /crm-form?uid=<sk>.
2. Site Config: Forms (ways A and B only)
Read the default site (repo_find on site, then repo_find_one) and look at data.features. Forms is on if the list has "forms", or a row { "feature": "forms" } that isn't enabled: false.
| Setting | /form and /form/<name> | The chosen page's address | What wraps the form | Emails link to |
|---|---|---|---|---|
| Off | 404 (correct: Forms is optional) | its own page | — | <site>/form (a 404) |
| On, no page chosen | the form | — | account-layout | <site>/form |
On, page X chosen | the form | /X?form=<name> is the form too | page X: first screen above, second below, at both addresses | <site>/X |
Tested with page skilltest-form-frame chosen: /form?form=<name>, /form/<name> and /skilltest-form-frame?form=<name> all drew the form between that page's two screens. /skilltest-form-frame with no form named showed "This form isn't available. No form was named in this link." GET /site/base-url?feature=forms gave <site>/skilltest-form-frame. The routing rules are in How a site's addresses route (Forms row and Exceptions).
To switch it on, follow How a site's addresses route step 3: the whole list, repo_update with patch, or update-partial with the dot-path key data.features. Read the list again right before writing it.
Stop: switching Forms on gives /form to the form feature, and choosing a page makes that page the frame for every form at both addresses. Its own content stops showing. Tell the person which addresses change, then wait for yes.
Hands on: the forms page's address (/form, or the chosen page).
Check: GET /site/base-url?feature=forms gives a url. curl -s -o /dev/null -w "%{http_code}" <site>/form is 200.
3. Way A: the platform form at /form
Nothing to build. The links:
| Link | Opens |
|---|---|
/form?form=<name> or /form/<name> | the form (the query wins over the segment) |
/form?collection=<collection> | a collection shared publicly in its own right (see the warning in Where answers land) |
…&code=<code> | a code form with the code applied, or a participant's own link |
…&token=<token> | an emailed-code or magic-link form opened from its email. The questions open at once, and the form's email question is answered with the verified address and skipped. |
…&email=<address> | an email form with the address given |
…&mode=group | one screen per schema group (fields with no group go under "General") instead of one per question |
…&embed=true (or =1) | the form alone for another site's iframe: no header, footer, cart, search or audio player; transparent background (components/embed/EmbedFrame.tsx, is-embed.ts) |
What the visitor sees. Every row except password was tested on the local site; password is from the code (SchemaFormRoute.tsx 209–222).
| Form | Screen |
|---|---|
none, or the gate passed | "Skilltest Open · 1 of 6 · Your name*", one question at a time, then Check your answers, then the thank-you |
code, no code | "Enter your access code" with Open form. A wrong code: "That access code is not right." |
emailed code / magic-link, no token | "What is your email address?" with Send me the link. It calls POST /api/client/forms/<name>/access and says "Check your email". |
email | "What is your email address?" with Continue; the address goes into the link as ?email= |
| participants, no code | "This form is by invitation. Open it from the link you were sent." |
password | "Sign in to open this form" → /login?redirect=<this link> |
| closed, unknown name | "This form isn't available" with the server's reason ("This form is closed.", "No form or collection found with name …") |
How the questions are drawn, from the schema (base-app components/schema-form/SchemaForm.tsx kindOf 146, collect 253, toSteps 281):
| Schema | Control |
|---|---|
enum / oneOf with const / options | lettered choice buttons (press A, B, C…); an array type picks several |
boolean | Yes / No |
integer with minimum and maximum up to 10 apart, or x-control: rating | a 1–N scale |
format: email, date, date-time, time, uri, tel, color, password | the matching input. A date-time answer is sent as a full timestamp. |
x-control: textarea, richtext, markdown, or maxLength over 180 | a paragraph box |
x-control: file / image | a file picker (see the warning) |
x-control: signature | draw or type, with consent |
type: "null" or x-control: paragraph / label / notice | a statement showing x-content; nothing to answer |
a nested object with properties (up to 3 deep) | its fields asked one by one, folded back into the object on submit |
hidden, readOnly, disabled, const, and id, sk, pk, datatype, author, createdate, modifydate, version, state, search | not asked |
schema.pages with more than one page | one screen per page, its fields together, titled by the page |
required (or inputRequired: true on the field), minLength / maxLength, minimum / maximum, pattern, errorMessage and a validations list are checked on each screen before moving on. The server checks the schema again on submit.
An uploaded file goes into the record itself. The platform form reads it as a data URL and sends { name, type, size, data: "data:…;base64,…" } in the JSON (SchemaForm.tsx 711–717). The engine saves it as it came. Tested: the test answer's values.doc.data held the base64 file. Large files bloat records and can hit the API's body limit. For documents, use a page that uploads to the file manager first (way C), or keep files small.
Hands on: the link to share: GET /site/base-url?feature=forms + ?form=<name>. Add &embed=true for an iframe.
Check: open the link in a browser. The first question (or the gate) shows inside the site's header and footer. Answer it once with a @test.local address and see the thank-you. Find the answer (Where answers land) and delete it.
4. Way B: a site page tied to a form
A page whose data.formName names a form is that form while Forms is on, at its own address (SchemaFormRoute.tsx isSchemaFormRoute 103). The page's first screen is drawn above the form and its second below, like a chosen Forms page. Use it for a form at its own address, e.g. /contact, inside the site's design.
Make the page with Build a website page, with two screens (the part above the form, the part below), then set formName:
{
"name": "contact", "slug": "contact", "site": "<site name>", "appType": "web", "title": "Contact us",
"formName": "contact",
"screens": [
{ "id": "top", "name": "Top", "slug": "top", "order": 0, "html": "<!DOCTYPE html>…<section class=\"intro\">…</section>…", "attributes": {}, "config": {} },
{ "id": "bottom", "name": "Bottom", "slug": "bottom", "order": 1, "html": "<!DOCTYPE html>…<section class=\"faq\">…</section>…", "attributes": {}, "config": {} }
],
"activeScreenId": "top",
"html": "<the first screen's document>"
}On an existing page, add only the field: repo_update on page with patch: { "formName": "<form name>" }, or update-partial with { "data.formName": "…", "data.name": "…", "data.site": "…", "data.slug": "…" }.
Build Studio has no field for formName. The page schema doesn't have it, so Page settings never shows it. Set it with repo_update. A page that has it opens in Build Studio like any other.
Tested on the local site:
- Forms on:
/skilltest-form-wrapdrew "SKILLTEST TOP SCREEN", the form, then "SKILLTEST BOTTOM SCREEN", inside the site's own header and footer. - Forms off: the same address showed only the page's first screen. No form, no error.
/skilltest-form-wrap?form=skilltest-form-codedrew a different form, the code-gated one.?form=beatsformName.- An ordinary page with
?form=(/news?form=…) stays itself. Only/form, the chosen Forms page andformNamepages take?form=.
There is no form component or preset to drop a form into a normal page. <wm-form> exists only in Content Studio posts (the Content Player renders it). The site's page renderer leaves it as an empty tag. The page runtime's form.* only serializes, validates and resets a <form>; it doesn't submit to a CRM form. A form inside a page's own content is way C.
Hands on: the page's address.
Check: open it. The form sits between the two screens. The emails still link to /form (step 2), not to this page.
5. Way C: a page of your own, posting through /api
The page is ordinary HTML in its screens. Its script goes in Page settings → Style → JavaScript (style.javascript), guarded by data-design-mode, as in Build a website page step 4. Forms can stay off.
The site's /api
fetch('/api/<path>') on the same site goes to the engine with the org and the site's app token added (base-app app/api/[...slug]/route.ts).
- Only the body, the query string and
Authorizationget through. Custom headers likex-form-tokenorx-form-codeare dropped. Put the code in the query (?token=) or the body. A signed-in visitor'sAuthorizationgoes on asx-client-authorization, which makes them the customer (route.ts 72–74,lib/appmint-client.ts234–237). - Errors come back wrapped:
{ "error": { "reason": "duplicate", "field": "email", "statusCode": 409, "error": "A … with email \"…\" already exists.", "path": "…", "method": "POST", "timeStamp": "…" }, "status": 409 }, with the engine's HTTP status. The message iserror.error, the reasonerror.reason(route.ts 131–138). Tested for every refusal above. - The query string is also copied into the body as
clientQuery; the form endpoints remove it. A body that holds nothing else is refused: "Form data is required". - The proxy adds the visitor's IP, host and agent as
x-client-info; the answer stores it asclient.
The flow, for a form that emails a code
- Collect the answers in your own steps.
POST /api/client/forms/<name>/accesswith{ email }, whereemailis trimmed and lowercased. Show "We sent a 6-digit code to …", a code box, Send a new code (the same call; each call makes a new pending code, and every unexpired one works) and Change email.POST /api/crm/form/submit/<name>?token=<code>with the answers. Send the same email in the answers; another address is refused with 403email-not-verified.- Show each
reasonfrom Refusal reasons. Show success only on a 2xx.
For a plain form (none), skip 2 and post the answers. For a shared code, send ?code=<code>.
A complete page (tested)
The screen's HTML:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width,initial-scale=1">
<style>
.st-apply { max-width: 520px; margin: 48px auto; padding: 0 16px; }
.st-apply label { display: block; margin: 12px 0 4px; font-weight: 600; }
.st-apply input, .st-apply select { width: 100%; padding: 10px; }
.st-msg[data-tone="error"] { color: #b91c1c; }
</style>
</head>
<body>
<main class="st-apply" id="st-apply">
<h1>Apply</h1>
<form id="st-details" novalidate>
<label for="st-name">Full name</label>
<input id="st-name" name="full_name" required>
<label for="st-email">Work email</label>
<input id="st-email" name="email" type="email" required>
<label for="st-team">Team</label>
<select id="st-team" name="team"><option>Red</option><option>Blue</option></select>
<button type="submit">Send me a code</button>
</form>
<form id="st-code" hidden novalidate>
<p id="st-sent"></p>
<label for="st-code-input">6-digit code</label>
<input id="st-code-input" name="code" inputmode="numeric" autocomplete="one-time-code" maxlength="6">
<button type="submit">Submit application</button>
<button type="button" id="st-resend">Send a new code</button>
</form>
<div id="st-done" hidden><h2>Application received</h2></div>
<p class="st-msg" id="st-msg" role="status"></p>
</main>
</body>
</html>Its style.javascript:
(function boot() {
// Never run inside Build Studio's canvas.
if (document.body && document.body.getAttribute('data-design-mode') === 'true') return;
var app = document.getElementById('st-apply');
if (!app) return void setTimeout(boot, 30);
if (app.dataset.bound) return;
app.dataset.bound = '1';
var FORM = 'skilltest-form-otp';
var details = document.getElementById('st-details');
var codeForm = document.getElementById('st-code');
var msg = document.getElementById('st-msg');
var answers = null;
function say(text, tone) { msg.textContent = text || ''; msg.setAttribute('data-tone', tone || ''); }
// POST through the site's own /api. Errors come back as { error: { reason, error, statusCode }, status }.
function api(path, body) {
return fetch('/api/' + path, {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify(body),
credentials: 'same-origin'
}).then(function (r) {
return r.json().catch(function () { return null; }).then(function (j) {
if (r.ok) return j;
var e = (j && typeof j.error === 'object' && j.error) || j || {};
var err = new Error(typeof e.error === 'string' ? e.error : (e.message || 'Request failed'));
err.status = r.status; err.reason = e.reason || '';
throw err;
});
});
}
function requestCode() {
return api('client/forms/' + FORM + '/access', { email: answers.email }).then(function () {
document.getElementById('st-sent').textContent = 'We sent a 6-digit code to ' + answers.email + '.';
details.hidden = true; codeForm.hidden = false; say('');
});
}
details.addEventListener('submit', function (ev) {
ev.preventDefault();
var f = new FormData(details);
answers = {
full_name: String(f.get('full_name') || '').trim(),
// The unique index compares exact text: lowercase before saving.
email: String(f.get('email') || '').trim().toLowerCase(),
team: String(f.get('team') || '')
};
if (!answers.full_name || !/^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(answers.email)) return say('Fill in your name and a full email address.', 'error');
requestCode().catch(function (e) { say(e.message, 'error'); });
});
document.getElementById('st-resend').addEventListener('click', function () {
requestCode().then(function () { say('A new code is on its way.'); }).catch(function (e) { say(e.message, 'error'); });
});
codeForm.addEventListener('submit', function (ev) {
ev.preventDefault();
var code = String(document.getElementById('st-code-input').value || '').trim();
// The code rides in the query string: the site's /api does not pass custom headers on.
var path = 'crm/form/submit/' + FORM + '?token=' + encodeURIComponent(code) + '&email=' + encodeURIComponent(answers.email);
api(path, answers).then(function () {
codeForm.hidden = true; document.getElementById('st-done').hidden = false; say('');
}).catch(function (e) {
if (e.reason === 'code-wrong') return say('That code is not right. Check the email and try again.', 'error');
if (e.reason === 'link-expired') return say('That code has expired. Send a new one.', 'error');
if (e.reason === 'link-required') return say('Enter the code from the email.', 'error');
if (e.reason === 'duplicate') return say('An application from this email already exists.', 'error');
if (e.reason === 'email-not-verified') return say('Use the email the code was sent to.', 'error');
say(e.message, 'error');
});
});
})();Tested in headless Chrome on the local site with Forms off. The form was bound to a collection with unique: true on email, its index built. The steps and what came back:
- Typed
Custom.Tester@test.local:accessgave 200 and the code box showed. 000000: 401, "That code is not right…"- The real code: 200, "Application received". The record was saved with the email lowercased and
owner: { datatype: "crm_form", id: "skilltest-form-otp" }. - The same email again with a fresh code: 409, "An application from this email already exists."
Collection-bound or plain
Plain form (no collection) | Collection-bound form | |
|---|---|---|
| Questions | the form's schema | the collection's schema |
| Saved as | form_submission (values) | a collection record, owner = the form |
| One per email | not available | unique: true on the field, then POST /repository/collections/fix (see Registration that creates the customer step 1). Tested: 409 duplicate. |
| Automation trigger | form_submitted | database_change on the collection, owner.id = form name |
| Emailed code used twice | refused for an inline magic-link link (already-submitted) | accepted for 72 hours (the pending row stays pending) |
- Unique fields compare exact text. Tested:
Reg.One@test.localandreg.one@test.localwere saved as two records. Lowercase the email in the page. - No passwords in a form record. A password in the answers is stored as plain text in the collection or
form_submission, readable by staff and exports. Account creation belongs to an automation; the customer sets a password through/login's "Forgot password?" or signs in with a magic link. See Registration that creates the customer. - Don't post to
/crm/contact-form/json/<app>/<name>from a page. It is the embed route for a form on an outside website. It hands the answers to the form's own submit, so the form's permission, dates, code, invitation, sign-in and schema all apply, but a<name>with no form or collection yet creates a new open form from the first post's fields (crm-form.service.tssaveContactFormJSON). A typo makes a stray form. Post to/api/crm/form/submit/<name>(or/api/client/forms/<name>/submit) as in the flow above.
Stop: the page is live at its address from its first save on a site that serves drafts. Show the person the address and the flow, and wait for yes. The code emails will carry an "Open the form" link to /form (see The emails); tell them.
Hands on: the page's address.
Check: go through it once with a @test.local address. Read the code from the engine instead of an inbox: repo_find on form_submission with { "data.formId": "<form sk>", "data.authentication.email": "<address>" }, and take data.authentication.token. A wrong code shows the code message, the right one shows success, and the record appears (Where answers land). Delete the test record and the pending form_submission.
When it's done
Tell the person:
- the way chosen and the address the form is at;
- who can fill it in (the
authenticationTypein their words: "anyone", "people we email a code to"); - where answers land (the form's Submissions in Studio, or the collection), and who is emailed for each;
- where the form's emails link, and, for way C, that the "Open the form" link goes to
/form, not their page; - whether Forms is on, and which addresses that gives to forms.
Open the form in Studio (/crm-form?uid=<sk>) and the page on the site.
What it can't do yet
- The emails can't link to a page of your own.
sendFormAccessandinviteParticipantsalways build<forms page>?form=…. Way C pages get an "Open the form" button that 404s or opens the platform form. - The code doesn't run out on a collection-bound form. The code stays good for 72 hours and can be used again. A unique field stops a second record under the same email.
- No "already applied" check before the code. The visitor learns about the duplicate only when they submit with the code.
- No upload of files to the file manager from the platform form. Files go into the record as base64.
- The confirmation email's subject starts with the site's host, not the business name. Tested: "phasite-phazzer.localhost:3200 - Skilltest File - Form Submission Received". The submission context has no
displayName. - The form's SEO tab isn't used by the site. No code in the site's form route or page metadata reads the form's
seo, so share previews of/formshow the forms page's own title and image. Not tested. - Build Studio can't set
formName, and there's no component to place a CRM form inside a page's content. - Studio's participant "Their link" is built as
<forms page>/form?form=…&code=…(crm-form-detail.tsx612), so with Forms on/formit reads/form/form?form=…. It still opens, because the query names the form. /crm/contact-form/json/<app>/<name>creates an open form named<name>on the first post to a name that has none (see the warning in step 5).
Don'ts
- Don't create a page named
formto "fix" a 404 at/form. Forms is off and the 404 is correct. Switch Forms on, or use way C. - Don't choose a page the site uses for something else as the Forms page. Its content becomes the frame around every form.
- Don't send the code in a header from a site page. Use
?token=or?code=. - Don't use
authenticationType: "email"when the address must be real. - Don't put
Gueston a bound collection'spermission. It opens the collection without the form's gate. - Don't put a password field in a form or its collection.
- Don't post to
/crm/contact-form/json/…from a page. - Don't read codes from real inboxes in tests. Use
@test.localaddresses and the pendingform_submission.