| id | 02261135-24fa-4d2f-9bc5-a7d2f5e6a975 | ||||
|---|---|---|---|---|---|
| blueprint | resource_apis | ||||
| title | Form Submission Repository | ||||
| nav_title | Form Submissions | ||||
| related_entries |
|
To work with the Form Submissions Repository, use the following Facade:
use Statamic\Facades\FormSubmission;| 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 |
FormSubmission::whereForm('postbox');FormSubmission::whereInForm(['postbox', 'newsletter']);FormSubmission::find($id);FormSubmission::query()
->where('form', 'postbox')
->where('email', 'hoff@statamic.com')
->get();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 falseForm submissions may also be created using the SubmitForm action, which handles file uploads, honeypot validation, event dispatching and sending emails.