Skip to content

Latest commit

 

History

History
87 lines (64 loc) · 2.11 KB

File metadata and controls

87 lines (64 loc) · 2.11 KB
id 02261135-24fa-4d2f-9bc5-a7d2f5e6a975
blueprint resource_apis
title Form Submission Repository
nav_title Form Submissions
related_entries
fdb45b84-3568-437d-84f7-e3c93b6da3e6
e4f4f91e-a442-4e15-9e16-3b9880a25522
bbea4454-efa2-4372-842b-b295376230f7
aea5645d-cffa-4029-b04e-58efcd4303e4

To work with the Form Submissions Repository, use the following Facade:

use Statamic\Facades\FormSubmission;

Methods

Methods Description
all() Get all form submissions.
whereForm($handle) Get submissions by form handle.
whereInForm($handles) Get submissions, across multiple forms. Accepts an array of form handles.
find($id) Get a form submission, by its submission ID.
make() Makes a new Submission instance
query() Query Builder

Querying

Examples {.popout}

Get form submissions by form

FormSubmission::whereForm('postbox');

Get form submissions, between multiple forms

FormSubmission::whereInForm(['postbox', 'newsletter']);

Get a single submission to a form by its id

FormSubmission::find($id);

Get form submissions, filtered by field

FormSubmission::query()
    ->where('form', 'postbox')
    ->where('email', 'hoff@statamic.com')
    ->get();

Creating

Start by making an instance of a form submission with the make method. You need to pass in a Form instance before you can save a form submission.

$form = \Statamic\Facades\Form::find('postbox');

$submission = FormSubmission::make()->form($form);

To set submission data, you may call the ->data() method and pass an array:

$submission->data([
    'name' => 'David Hasselhoff',
    'email' => 'hoff@statamic.com',
]);

Finally, save it. It'll return a boolean for whether it succeeded.

$submission->save(); // true or false

Form submissions may also be created using the SubmitForm action, which handles file uploads, honeypot validation, event dispatching and sending emails.