Events & Hooks
FilaForms dispatches events at key points in the form lifecycle. Use standard Laravel event listeners to hook into form submissions, send custom notifications, sync data, or trigger workflows.
FormSubmitted Event
Dispatched after a form submission is successfully processed and stored.
Properties:
| Property | Type | Description |
|---|---|---|
$form | Form model | The form that was submitted |
$submission | FormSubmission model | The stored submission record |
use FilaForms\Core\Events\FormSubmitted;
class SyncToCrm
{
public function handle(FormSubmitted $event): void
{
$form = $event->form;
$submission = $event->submission;
$data = $submission->data['custom_fields'];
// Sync to your CRM, send to Slack, etc.
}
}
Registering Listeners
Register in your EventServiceProvider:
use FilaForms\Core\Events\FormSubmitted;
use App\Listeners\SyncToCrm;
protected $listen = [
FormSubmitted::class => [
SyncToCrm::class,
],
];
Or register inline in a service provider:
use FilaForms\Core\Events\FormSubmitted;
use Illuminate\Support\Facades\Event;
Event::listen(FormSubmitted::class, function (FormSubmitted $event) {
logger()->info('Form submitted', [
'form' => $event->form->name,
'submission_id' => $event->submission->id,
]);
});
Built-in Listener
SendFormNotifications listens to FormSubmitted automatically. It handles admin email notifications, auto-responses to submitters, and in-app notifications. It implements ShouldQueue and runs on the queue.
SendFormNotifications yourself. It is registered by the package and respects the notification settings configured on each form.Custom Models
Override the default FilaForms models to add custom behavior, relationships, or scopes.
use FilaForms\Core\FilaForms;
use App\Models\CustomForm;
use App\Models\CustomSubmission;
use App\Models\CustomEvent;
FilaForms::useFormModel(CustomForm::class);
FilaForms::useSubmissionModel(CustomSubmission::class);
FilaForms::useEventModel(CustomEvent::class);
Custom models should extend the base FilaForms models:
use FilaForms\Core\Models\Form;
class CustomForm extends Form
{
// Add custom relationships, scopes, etc.
}
Post-Submit Actions
Register custom actions that run after a submission is stored. Actions implement the PostSubmitActionHandler contract.
use FilaForms\Core\Contracts\PostSubmitActionHandler;
FilaFormsPlugin::make()
->registerPostSubmitAction(new CustomPaymentAction())
->defaultPostSubmitAction('custom_payment');
Table Customization
Customize the forms and submissions tables in the admin panel.
FilaFormsPlugin::make()
->configureFormsTable(function ($table) {
return $table->defaultSort('created_at', 'desc');
})
->configureSubmissionsTable(function ($table) {
return $table->poll('10s');
});