WIP: form attachments — agent guide, skills, seed template, changelog
Co-Authored-By: Claude Fable 5.2 <[email protected]>
This commit is contained in:
co-authored by
Claude Fable 5.2
parent
344574d6bd
commit
b7fb1b0e31
@@ -62,6 +62,7 @@ Underneath is `BuilderForm` (client) — clean, accessible HTML **without styles
|
||||
checkbox, **Checkbox group** (multiple choice, min/max), message, **Step** (splits into steps),
|
||||
country, state (on by default in form-builder, rendered as a text field).
|
||||
Turning a type off: `forms.fields: { country: false, state: false }`.
|
||||
With `forms: { attachments: true }` there is also **File** (section 3a).
|
||||
- **Multi-step form:** the editor inserts a **Step** block (title, description) — the fields below it form one
|
||||
screen. The Next/Back buttons and "Step 1 of 3" come from **Form messages → Form messages** (next, back,
|
||||
stepOf). Next validates only the current step; a server error returns to the step with the field; focus
|
||||
@@ -82,6 +83,38 @@ Custom field type in the panel: the `FormsOption['fields']` type only accepts `b
|
||||
(at runtime the block object passes through to form-builder, but TS rejects it), and the server treats
|
||||
an unknown type as text anyway — if you need a custom type or validation → **plugin gap** (`ipal-plugin-gap`).
|
||||
|
||||
## 3a. A file on a form (CV, specification, photo) — `forms.attachments`
|
||||
The file is **e-mailed to the company and never stored**: no Media record, no bucket, no disk, no download link.
|
||||
Never build this by hand (your own `<input type="file">`, upload route or upload collection = an error).
|
||||
|
||||
1. Config: `forms: { attachments: true }` (defaults: 10 MB per file and per submission, at most 3 files per field).
|
||||
Options (`FormAttachmentsOption`): `maxSizeMB`, `maxTotalMB`, `maxFiles`, `fileTypes` (add / replace / `false`),
|
||||
`allowRisky`, `scan` (antivirus hook), `strictPdf`, `notice`, `maxConcurrent`, `path`, `submit`
|
||||
(`maxPerMinute`, `clientIp`, `honeypotField`, `turnstileHostnames`, `turnstileOnConfigError`, `allowedOrigins`).
|
||||
Postgres: `pnpm payload migrate:create`; then `pnpm generate:types`.
|
||||
2. Form: a **File** field — in the seed
|
||||
`{ blockType: 'file', name: 'attachment', allowedTypes: ['pdf', 'doc', 'docx'], maxSizeMB: 10, maxFiles: 1, label: {…}, help: {…} }`
|
||||
(the template has the line, commented). Types: `pdf`, `doc`, `docx`, `odt`, `rtf`, `xls`, `xlsx`, `jpg`, `png`, `webp`.
|
||||
The label and the help text ("PDF or DOCX, up to 10 MB") are written per language in the panel / seed.
|
||||
3. E-mails: the file goes to **every e-mail whose To / CC / BCC are fixed addresses** — the company notification.
|
||||
An e-mail addressed with `{{email}}` (the confirmation to the customer) never gets it. A form with a File field
|
||||
and no fixed-recipient e-mail cannot be saved. `{{attachment}}` / `{{*:table}}` show the file name.
|
||||
4. Code: nothing. `RenderForm` renders the field (native input, help text, file list, "Remove" button), and the
|
||||
browser posts files to the plugin's endpoint `POST /api/ipal/forms/submit` — no route file, no `next.config`
|
||||
change. Classes: `file`, `help`, `fileList`, `fileItem`, `fileRemove` in `formClasses.ts`. Your own markup:
|
||||
`f.getFileProps(field)`, `f.getFiles(field)`, `f.removeFile(field, i)`, `f.helpId(field)`.
|
||||
5. Texts: Form messages → **Files** (`fileTooLarge`, `fileType`, `fileCount`, `fileNotSent`, `fileRemove`) —
|
||||
English and Polish defaults; fill every other language of the site.
|
||||
6. Mail size: **Site integrations → E-mail sending → Test e-mail** with **Attach a 10 MB test file** must arrive.
|
||||
SMTP: the provider's limit decides (a 10 MB server limit carries only ~7 MB of file — lower the field's
|
||||
maximum). Microsoft Graph: files of 3 MB and more need the `Mail.ReadWrite` permission on the agency app
|
||||
(email.md "Attachments"); without it they go over SMTP when the panel has SMTP settings, else the form's limit
|
||||
drops to about 2.8 MB by itself. Keep Graph small on purpose: `mailAdapter({ graph: { largeAttachments: false } })`.
|
||||
|
||||
Tell the client plainly: **there is no antivirus scan** (the e-mail says so), the macro check of old `.doc` / `.xls`
|
||||
files is best-effort, and when the e-mail cannot be sent the file is gone — the visitor sees "We could not send your
|
||||
file", staff get a notice without the file, and the submission shows **File delivery: Not sent**.
|
||||
|
||||
## 4. Page — block data once (blocks do not import `lib/*`)
|
||||
From `createPageRoute` (PROGRAMISTA §2.8):
|
||||
```tsx
|
||||
@@ -144,6 +177,10 @@ Details the seed already covers, which you check after every manual change in th
|
||||
- [ ] second language → labels and messages in that language;
|
||||
- [ ] GTM Preview → an event with the name from the panel after success;
|
||||
- [ ] multi-step form: Next with an empty step → errors, the step stays; Back keeps the entered values;
|
||||
- [ ] form with a **File** field: a PDF arrives attached to the company e-mail, the customer e-mail has no file,
|
||||
the submission shows *Files* and *File delivery: Handed to the mail server*, Media has no new record;
|
||||
a `.exe` renamed to `.pdf` → "…is not an accepted file type", no submission; a file over the limit → the
|
||||
size message before sending; keyboard only: Tab to the field, pick a file, Tab to "Remove …", Enter removes it;
|
||||
- [ ] `ipal-audit --quick` → zero hardcoding in FormBlock, no copy of the form engine;
|
||||
- [ ] `ipal-consent-check` → still 0 violations (Turnstile is necessary, not tracking).
|
||||
|
||||
@@ -155,6 +192,10 @@ Details the seed already covers, which you check after every manual change in th
|
||||
| `reason: 'validation'`, `kind: 'unknown_fields'` | the frontend sends a field the form does not have (custom renderer with an extra field, typo in `name`) |
|
||||
| "Next/Back" buttons in English | empty Form messages → next / back / stepOf in that language |
|
||||
| `reason: 'not_found'` | `formId` from another database (seeded on dev, another ID on prod) — use a relationship from the panel, not a fixed ID in code |
|
||||
| "We could not send your file", submission says *Not sent* | the mail server refused the message (size limit: see the note on the submission), or Graph without `Mail.ReadWrite` and no SMTP settings → Test e-mail with the 10 MB file; lower the field's maximum or fix the transport (email.md "Attachments") |
|
||||
| the form with a File field cannot be saved ("Add an e-mail with a fixed recipient…") | every e-mail of the form is addressed with a placeholder → add the company notification with a fixed address |
|
||||
| the File field does not appear in the builder | `forms.attachments` is off, or `forms.fields.file: false` |
|
||||
| a file is refused although its type is ticked | the content does not match the extension, the name has a second extension (`cv.pdf.docx`), the document has macros, or it is password-protected |
|
||||
| submission exists, no email | missing `email: mailAdapter()`, empty Emails tab, transport in the panel; server logs |
|
||||
| always `turnstile` | wrong key pair / domain in Cloudflare (BuilderForm resets the token after an error) |
|
||||
| the page became dynamic (`ƒ`) | `headers()` in a component instead of in the action |
|
||||
|
||||
@@ -27,6 +27,12 @@ export const formClasses: BuilderFormClassNames = {
|
||||
choices: 'grid gap-2', // radio / checkbox group <fieldset>
|
||||
legend: 'mb-1 font-medium text-fg-strong',
|
||||
choice: 'flex items-center gap-2',
|
||||
// File field (forms.attachments): the native input, its help text, the list of picked files.
|
||||
file: 'block w-full text-fg file:mr-3 file:rounded-control file:border-0 file:bg-surface-muted file:px-3 file:py-2 file:text-fg-strong',
|
||||
help: 'mt-1 text-sm text-fg-muted',
|
||||
fileList: 'mt-2 grid gap-1 text-sm',
|
||||
fileItem: 'flex flex-wrap items-center gap-2',
|
||||
fileRemove: 'underline underline-offset-2',
|
||||
error: 'mt-1 text-sm text-danger',
|
||||
formError: 'rounded-control bg-danger-surface p-4 text-danger',
|
||||
actions: 'flex flex-wrap gap-3',
|
||||
|
||||
@@ -44,6 +44,11 @@ const FORM = {
|
||||
// options: [{ value: 's', label: { pl: 'do 10 tys.', en: 'up to 10k' } }, …] },
|
||||
// { blockType: 'checkboxGroup', name: 'services', maxSelected: 3, label: {…}, options: [ …same shape… ] },
|
||||
// { blockType: 'date', name: 'deadline', label: { pl: 'Termin', en: 'Deadline' } },
|
||||
// A file sent to the company by e-mail — never stored on the site (needs `forms: { attachments: true }`).
|
||||
// It rides on the notification below (fixed recipient); the confirmation to {{email}} never carries it.
|
||||
// { blockType: 'file', name: 'attachment', required: false, width: 100, allowedTypes: ['pdf', 'doc', 'docx'],
|
||||
// maxSizeMB: 10, maxFiles: 1, label: { pl: 'Załącznik (opcjonalnie)', en: 'Attachment (optional)' },
|
||||
// help: { pl: 'PDF, DOC lub DOCX, do 10 MB', en: 'PDF, DOC or DOCX, up to 10 MB' } },
|
||||
// GDPR consent — name MUST stay `consent`; never pre-ticked (the plugin enforces it server-side).
|
||||
{
|
||||
blockType: 'checkbox',
|
||||
|
||||
Reference in New Issue
Block a user