Form files: the visitor is told when the problem is the file — why and what to do; UTF-8 file names

Co-Authored-By: Claude Fable 5.2 <[email protected]>
This commit is contained in:
Radosław Smoliński
2026-11-13 16:51:05 +01:00
co-authored by Claude Fable 5.2
parent b6f9f34705
commit 97202ee03e
18 changed files with 335 additions and 128 deletions
+9 -4
View File
@@ -24,18 +24,23 @@ once there are more than 20.
- **E-mail:** the file goes to every e-mail of the form whose recipients are fixed addresses from the panel; an
e-mail addressed with a placeholder (the confirmation to the visitor) never carries it. `{{field}}`, `{{*}}` and
`{{*:table}}` show the file name.
- **A failed send is visible:** the visitor sees "We could not send your file…" and can retry, staff get the
- **The visitor is told when the problem is the file:** too large (with the limit), a format the field does not
take (with the formats), a refused file (a program, an archive, macros, content that does not match), too many
files, or a file that could not be e-mailed. Each message names the file, says what to do, shows at the File
field, and on an optional field adds "You can also send the form without the file." What the visitor typed
stays in the form. A failure that is not about the file keeps its own message.
- **A failed send is visible:** the visitor sees "We could not send the file …" and can retry, staff get the
notification without the file, the submission is marked **File delivery: Not sent**. A repeated request
(double click, a resend) sends nothing twice.
- Browser: `RenderForm` / `BuilderForm` render a native file input with help text, the list of picked files and
a "Remove" button; `useBuilderForm` gains `getFileProps`, `getFiles`, `removeFile`, `helpId`,
`getHoneypotProps`; new `classNames` keys `file`, `help`, `fileList`, `fileItem`, `fileRemove`.
- New texts in Form messages → **Files** (`fileTooLarge`, `fileType`, `fileCount`, `fileNotSent`, `fileRemove`),
English and Polish defaults.
- New texts in Form messages → **Files** (`fileTooLarge`, `fileType`, `fileRefused`, `fileCount`, `fileNotSent`,
`fileOptional`, `fileRemove`), English and Polish defaults.
- New exports: `buildFileBlock`, `fileBlock`, `FORM_FILE_TYPES`, `RISKY_FILE_EXTENSIONS`, `formatFileSize`,
`mailAttachmentLimit` (root); `fileFieldRules`, `fileFieldError`, `formatFileSize` (`/client`);
`splitFormFiles` (`/server`); `submitForm({ files, attemptKey })`; result codes `kind: 'file_too_large' |
'file_type' | 'file_count'` and `reason: 'delivery'`.
'file_type' | 'file_refused' | 'file_count'` and `reason: 'delivery'`.
- **Attachments over both e-mail transports** ([email.md](./email.md) "Attachments"). SMTP passes them through.
Microsoft Graph sends attachments under 3 MB in the one `sendMail` call; larger ones go through a draft and an
upload session, and the copy the mailbox keeps is deleted afterwards. That path needs the `Mail.ReadWrite`
+10 -7
View File
@@ -103,8 +103,10 @@ Never build this by hand (your own `<input type="file">`, upload route or upload
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.
5. Texts: Form messages → **Files** (`fileTooLarge`, `fileType`, `fileRefused`, `fileCount`, `fileNotSent`,
`fileOptional`, `fileRemove`) — English and Polish defaults; fill every other language of the site. Each tells
the visitor that the problem is the **file**, why, and what to do (a smaller file, another format; on an
optional field also "send the form without the file"). They show at the File field; what the visitor typed stays.
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
@@ -112,8 +114,8 @@ Never build this by hand (your own `<input type="file">`, upload route or upload
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**.
files is best-effort, and when the e-mail cannot be sent the file is gone — the visitor sees "We could not send the
file …" at the File field, 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):
@@ -179,8 +181,9 @@ Details the seed already covers, which you check after every manual change in th
- [ ] 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;
a `.exe` renamed to `.pdf` → "The file … was refused: …" at the File field, no submission, the typed answers
still there; a file over the limit → "…is too large. Choose a file of up to N MB." before sending; each
message in every language of the site; 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).
@@ -192,7 +195,7 @@ 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") |
| "We could not send the 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 |
+26 -10
View File
@@ -211,7 +211,7 @@ ipalKit({ forms: { attachments: true } }) // adds the File field to the form
**Verify:** submit the form with a PDF → the confirmation shows; the company e-mail has the file attached and the
line "…was not checked for viruses"; the confirmation e-mail to the visitor has no file; Form Submissions shows
**Files** (name, type, size) and **File delivery: Handed to the mail server**. Rename a `.exe` to `.pdf` and submit →
the field shows "…is not an accepted file type", nothing is stored or sent.
the File field shows "The file … was refused: …", nothing is stored or sent.
### Options (`FormAttachmentsOption`)
@@ -294,8 +294,9 @@ characters, the extension of the detected type (`CV Jan Kowalski.pdf`; an empty
The file is not kept, so there is nothing to retry with. Then:
- the **visitor** sees an error — Form messages → **File not sent** ("We could not send your file. Try again, or
send it by e-mail.") — keeps their answers and the selected file, and can try again. No confirmation e-mail goes out;
- the **visitor** sees an error **at the File field** — Form messages → **File not sent** ("We could not send the
file "cv.pdf". Choose a smaller file or another format and try again.") — keeps their answers and the selected
file, and can try again. The mail server's own words never reach the visitor. No confirmation e-mail goes out;
- **staff** get the notification once more **without** the file: "The visitor attached a file: … but it could not
be sent. Ask them to send it again.";
- the **submission** is stored and marked **File delivery: Not sent**, with a note (the mail server's reason). The
@@ -308,12 +309,27 @@ refuses it) cannot be seen by the site; it arrives in the sender mailbox.
(double click, a resend by the browser or a proxy) gets the first answer and sends nothing again. The plugin sends
each e-mail once — there is no automatic resend.
### Result codes and messages
### What the visitor is told
`reason: 'validation'` with `kind: 'file_too_large' | 'file_type' | 'file_count'` (+ `field`, `label`, `file`,
`max`, `types`), `kind: 'required'` for a required File field without a file, and `reason: 'delivery'` when the
e-mail could not be sent. Texts: Form messages → **Files** (`fileTooLarge`, `fileType`, `fileCount`, `fileNotSent`,
`fileRemove`), defaults in English and Polish, per language in the panel ([notifications.md](./notifications.md)).
**When a submission fails because of the file, the message says it is the file, why, and what to do** — and it
shows at the File field (the result carries `field`). Everything the visitor typed stays in the form.
| Problem | Code | Text (Form messages → Files) | English default |
|---|---|---|---|
| too large | `kind: 'file_too_large'` (`file`, `max`) | `fileTooLarge` | The file "cv.pdf" is too large. Choose a file of up to 10 MB. |
| a format the field does not take | `kind: 'file_type'` (`file`, `types`) | `fileType` | The file "cv.txt" is in a format we do not accept. Choose one of: PDF, DOC, DOCX. |
| refused: a program, an archive, macros, a doubled extension, content that does not match the type, the scanner said no | `kind: 'file_refused'` (`file`, `types`) | `fileRefused` | The file "cv.docx" was refused: it is a program or an archive, it holds macros, or its content does not match its type. Choose another file (PDF, DOC, DOCX). |
| too many files | `kind: 'file_count'` (`max`) | `fileCount` | Too many files in "Attachment". Remove some: the limit is 1. |
| the e-mail with the file could not be sent | `reason: 'delivery'` (`field`, `file`) | `fileNotSent` | We could not send the file "cv.pdf". Choose a smaller file or another format and try again. |
- On a File field that is **not required**, every one of these ends with `fileOptional` — "You can also send the
form without the file." (the result carries `optional: true`).
- A required File field left empty is `kind: 'required'` → the ordinary field text ("Check the field …").
- A failure that is **not** about the file keeps its own text: consent, a field error, the rate limit, the
general error.
- The texts are in the panel like every form message: Form messages → **Files**, per language, with English and
Polish defaults — fill the other languages of the site ([notifications.md](./notifications.md)). The browser
shows the size, format and count messages before anything is sent; the server answers with the same texts.
### Your own markup
@@ -556,8 +572,8 @@ type SubmitFormResult =
| { success: true; submissionId: string | number }
| { success: false; reason: 'rate_limited' }
| { success: false; reason: 'turnstile' }
| { success: false; reason: 'validation'; field?: string; kind?: 'invalid_format' | 'required' | 'too_long' | 'unknown_fields' | 'file_too_large' | 'file_type' | 'file_count'; file?: string; max?: number; types?: string }
| { success: false; reason: 'delivery'; submissionId?: string | number } // the file could not be e-mailed
| { success: false; reason: 'validation'; field?: string; kind?: 'invalid_format' | 'required' | 'too_long' | 'unknown_fields' | 'file_too_large' | 'file_type' | 'file_refused' | 'file_count'; file?: string; max?: number; types?: string; optional?: boolean }
| { success: false; reason: 'delivery'; field?: string; file?: string; optional?: boolean; submissionId?: string | number } // the file could not be e-mailed
| { success: false; reason: 'not_found' }
| { success: false; reason: 'consent'; field?: string }
| { success: false; reason: 'error' }
+12 -7
View File
@@ -61,17 +61,22 @@ per language.
With `forms.attachments` ([forms.md](./forms.md) "Files") the **Files** group of Form messages holds:
Each one tells the visitor that the problem is the file, why, and what to do next.
| Key | Placeholders | English default |
|---|---|---|
| `fileTooLarge` | `{file}`, `{max}` (MB) | `"{file}" is too large. The limit is {max} MB.` |
| `fileType` | `{file}`, `{types}` | `"{file}" is not an accepted file type. Accepted: {types}.` |
| `fileCount` | `{field}`, `{max}` | `Attach at most {max} files in "{field}".` |
| `fileNotSent` | — | `We could not send your file. Try again, or send it by e-mail.` |
| `fileTooLarge` | `{file}`, `{max}` (MB) | `The file "{file}" is too large. Choose a file of up to {max} MB.` |
| `fileType` | `{file}`, `{types}` | `The file "{file}" is in a format we do not accept. Choose one of: {types}.` |
| `fileRefused` | `{file}`, `{types}` | `The file "{file}" was refused: it is a program or an archive, it holds macros, or its content does not match its type. Choose another file ({types}).` |
| `fileCount` | `{field}`, `{max}` | `Too many files in "{field}". Remove some: the limit is {max}.` |
| `fileNotSent` | `{file}` | `We could not send the file "{file}". Choose a smaller file or another format and try again.` |
| `fileOptional` | — | `You can also send the form without the file.` — added to the five above when the File field is not required |
| `fileRemove` | `{file}` | `Remove {file}` |
Polish defaults ship too; any other language is filled in the panel. `resolveFormMessage` maps
`kind: 'file_too_large' | 'file_type' | 'file_count'` and `reason: 'delivery'` to them; a texts object without these
keys falls back to `validation` / `error`.
Polish defaults ship too; any other language is filled in the panel (an empty field falls back to English there).
`resolveFormMessage` maps `kind: 'file_too_large' | 'file_type' | 'file_refused' | 'file_count'` and
`reason: 'delivery'` to them and appends `fileOptional` when the result says `optional`; a texts object without
these keys falls back to `validation` / `error`. The result carries `field`, so the message shows at the File field.
## {field} interpolation