Showing answers
The detail page of a submission shows the answers in the shape of the form:
under the form's titles, each field at the width it has on the canvas, a hidden
field marked as such and an unanswered one as a dash. An answer reads as text
by default, a link for an email address or phone number, labels for a list of
choices, a check for a checkbox; a field that fills several columns shows them
together, and an upload shows its files. "As a list" turns this into one row
per answered field with its key, and the page remembers that choice for the
session. The values a form type adds itself (extraValues()) show with the
submission's details instead, since nobody answered them.
A field can format its answer. The callback receives the value and the submission, never an empty answer, and what it returns is what the table, the detail page, the export and the mails show. An array becomes labels on the detail page and a comma-separated list everywhere else:
NumberField::make('hours')
->formatAnswerUsing(fn (int $value, FormSubmission $submission): string => "{$value} hours a week")For something richer on the detail page only, give the field a Blade view of
its own. It receives $value (formatted), $raw (as stored), $field,
$submission and $answer, a SubmissionAnswer:
BranchField::make('branch')->answerView('answers.branch')A field type sets the default for all its fields in $answerView, which the
built-in views filament-form-builder::answers.text, .email, .phone,
.boolean and .columns use too.
Every submission keeps a snapshot of the form's fields as they were when it was submitted, down to the title each sat under and its width, so its answers keep the layout they came in with: a field added since is left out, and one moved since stays where it was. The answers to a field that has since been removed show apart, under the label they had, and a choice still reads as the option's label. A key the snapshot does not know shows under its own name. The export of a form puts these answers together in an "Other data" column, one per line.
A submission also keeps where it came from: the page its form was on, and in
meta the browser, the language of the site, the signed-in user, the
utm_* parameters of the page and, only when switched on, the IP address.
The details on its page show them, and the submission tables and the export
offer them as columns, off until someone ticks them. The submission_meta
config turns each on or off, its column with it; an IP address is personal
data, so ip is false by default, or 'anonymized' (without its last part)
or 'full'.
A submission counts as read once someone opens its page, stored in read_at
without touching updated_at or firing an update. Unread ones show an
envelope and bold text in the tables, the navigation and a form's Submissions
tab count them, and the tables filter and mark them in bulk. The page itself
can mark one unread again and steps to the newer and older submission of the
same form, also with the k and j keys.
How long submissions are kept
Submissions stay until someone deletes them, unless retention_months in the
config is set: every night the ones older than that go, with their files and
including trashed ones. A form can keep them shorter, longer or forever under
"Keep submissions" in its details, and its Submissions tab says for how long.
The package schedules model:prune for this, so the app's scheduler has to
run; without it nothing is deleted.
