Events reference
Overview
WebForms dispatches Magento events at the points where other modules most often need to react: a submission
saved, validated, approved or moved to another status, a form copied or imported, a field rendered. This page
lists each event with the place it fires and its payload. Read a payload value with
$observer->getData('<key>') or the matching magic getter, for example $observer->getResult().
The storefront scripts fire browser events of their own, such as mm_webform_loaded; those are on
Frontend APIs. For plugins and the registries WebForms reads from DI, see
Events, plugins and registries.
Authentication
Events need no credentials: an observer runs inside Magento, in the request or command that dispatches the event.
The area decides which observers run. Declare an observer in etc/events.xml to receive the event wherever it
fires, or in etc/frontend/events.xml, etc/adminhtml/events.xml or etc/webapi_rest/events.xml to receive it
only in that area. The Area column below says where each event can fire; an event marked Admin never
reaches an observer declared only in etc/frontend/events.xml.
Operations
Submissions
| Event | Area | Fires | Payload |
|---|---|---|---|
webforms_validate_post_result | Any | After the fields of a posted submission are validated and before it is saved. Also on the Review Before Submit step, where nothing is saved. Dispatched in Helper\Result\PostHelper. | form (the form), postData (array, the posted values), validate (a DataObject; its errors key holds the error list). To refuse the submission, read errors, append a message and write the array back with setData('errors', …). postData is a copy: changing it doesn't change what is saved. |
webforms_result_save | Any | On every save of a submission through its resource model, new or existing: storefront and admin submissions, admin and API edits. Inside the save transaction, after the answers are written. Dispatched in Model\ResourceModel\Result::_afterSave(). | result (the submission). |
webforms_result_submit | Any | Near the end of the submission pipeline, after the save, the spending of a solved CAPTCHA, the initial status and announcement of a new submission, and the per-field processing. An exception in one of those steps leaves the submission saved without this event. Pipeline callers: the storefront form, the REST and GraphQL submit calls, the admin's new submission and the admin edit form. Dispatched in Helper\Result\PostHelper. | result (the submission), is_new (bool: true when this call created the submission, false for an edit). |
webforms_result_load | Any | After a submission and its answers are loaded. Dispatched in Model\ResourceModel\Result::_afterLoad(). | result. |
webforms_result_delete | Any | Before a submission is deleted, after its messages and uploaded files are removed. Dispatched in Model\ResourceModel\Result::_beforeDelete(). | result. |
webforms_result_collection_load | Any | After a submission collection is loaded. Dispatched in Model\ResourceModel\Result\Collection::_afterLoad(). | collection. |
webforms_result_approve | Admin, REST | After a submission's approval status changes: the admin's status control (Controller\Adminhtml\Result\SetStatus), the mass status actions (once per changed submission, Model\Result\Mass\BulkUpdate::approve()), and the REST approval update in the WebForms API module (Model\Service\Submission). | result (the updated submission; the mass actions load each one again after the database update). |
webforms_result_status_changed | Any | After one submission moves to another workflow status, once the change is committed: the admin's status control, the REST status update, and a customer's emailed reply when the store moves the submission on reply. Dispatched in Model\Status\AssignmentService. | result_id (int), old_status_id (int or null), new_status_id (int or null), actor_id (admin user id, or null when no admin made the change). |
webforms_result_status_mass_changed | Admin | Once per mass status change from the submissions grid that changed at least one submission, for the submissions that actually changed. Dispatched in Model\Status\AssignmentService. | new_status_id, result_ids (array of int), actor_id, counts (array of three ints: changed, unchanged, failed). |
webforms_controller_result_access | Storefront | When WebForms decides whether a customer owns a submission (My Account, printing, replies, editing), once per request, submission and capability. Dispatched in Model\Customer\Access\OwnershipHook::isOwner(). | access (a DataObject; its allowed key holds the decision, preset to strict ownership), result, capability (WebForms passes view, reply, edit, delete or print). Set allowed to grant a delegate or to refuse the owner. |
To act on a new submission, observe webforms_result_submit and check is_new. webforms_result_save also
fires for every later edit of the same submission.
Forms and fields
| Event | Area | Fires | Payload |
|---|---|---|---|
webforms_form_duplicate | Admin, REST | After a form is copied with its sections, fields and logic: Duplicate in the admin or the REST API, and also each time the builder copies a form into a draft, keeps a version or copies a version back into a draft. Dispatched in Model\Form::clone(). | form (the new form), elementMatrix (array: field_<old id> → new field id, fieldset_<old id> → new section id). |
webforms_form_import | Admin, REST | After a form is imported in the admin or created from a form document through the REST API. A form created from a starter template doesn't fire it. Dispatched in Helper\Form\ImportHelper. | form (the imported form), elementMatrix (array: field_<id in the file> and field_<field code> → new field id, fieldset_<id in the file> → new section id). |
webforms_fields_tohtml_html | Storefront | After one field's storefront HTML is rendered. Dispatched in Model\Field\AbstractField::toHtml(). | field (the field), html_object (a DataObject; change its html key to replace the markup). |
webforms_form_prepare_save | Admin | Before the classic form settings page saves a form. Dispatched in Controller\Adminhtml\Form\Save. | form, request. |
webforms_builder_draft_activity | Admin | After a builder action on a draft, to mark the draft as still in use. Dispatched in Controller\Adminhtml\AbstractBuilderJsonAction. | form_id (int, the draft). |
Admin screens
| Event | Area | Fires | Payload |
|---|---|---|---|
webforms_fieldset_prepare_save | Admin | Before the admin's submission edit form saves a submission. Despite the name, it is about a submission. Dispatched in Controller\Adminhtml\Result\Save. | result (the submission), form, request. |
webforms_quickresponse_prepare_save | Admin | Before a quick response is saved, and before a quick response category is saved. Dispatched in Controller\Adminhtml\Quickresponse\Save and Controller\Adminhtml\QuickresponseCategory\Save. | form (the quick response or the category being saved, under this key in both cases), request. |
webforms_block_adminhtml_results_edit_form_prepare_layout_field | Admin | For each field while the admin submission edit form is built, before the field's input is made. Dispatched in Ui\Component\Result\Form\Modifier\Answers, since the edit form is the UI component webforms_result_form. | field, config (a DataObject with the input's type and settings); form and fieldset are null. |
webforms_ui_component_result_listing_columns_prepare_config | Admin | For each field column of the submissions grid. Dispatched in Ui\Component\Result\Listing\Columns. | field, column_config (a DataObject with class and arguments; change them to replace the column). |
webforms_integration_lists_refreshed | Admin | After the admin asks an integration's settings on a form to reload the lists from the service. Dispatched in Ui\Component\Form\Form\Modifier\Integration\AbstractIntegrationSettings. | code (the integration), store_id, form, outcomes (array keyed by list; each value is served, not_loaded, failed or busy), labels (each list's name, keyed by list). |
Uploaded files
Each kind of stored file fires its own event before its row is deleted, after the file and its thumbnails are
removed. Dispatched in Model\ResourceModel\AbstractFile::_beforeDelete(). Area: any. Payload: file.
| Event | File |
|---|---|
webforms_files_delete | A file uploaded with a submission. |
webforms_dropzone_delete | A temporary upload, not yet attached to a submission. |
webforms_file_gallery_delete / webforms_tmp_file_gallery_delete | An image of a Gallery field, stored and temporary. |
webforms_file_message_delete / webforms_tmp_file_message_delete | An attachment of a reply message, stored and temporary. |
webforms_file_customer_notification_delete / webforms_tmp_file_customer_notification_delete | An attachment of the customer notification, stored and temporary. |
Model events
These models set their own event prefix, so Magento's standard model events fire under it:
<prefix>_load_before, <prefix>_load_after, <prefix>_save_before, <prefix>_save_after,
<prefix>_save_commit_after, <prefix>_delete_before, <prefix>_delete_after and
<prefix>_delete_commit_after. Payload: object and data_object, both the model.
| Prefix | Model |
|---|---|
webforms_result | A submission. |
webforms_result_snapshot | The stored snapshot of a submission. |
webforms_message | A reply message on a submission. |
webforms_logic | A logic rule. |
webforms_store | The store view settings of a form or one of its parts. |
webforms_status, webforms_statistics | A workflow status; a statistics counter. |
webforms_quickresponse, webforms_quickresponse_category | A quick response and its category. |
webforms_notification, webforms_notification_content, webforms_notification_condition, webforms_notification_target, webforms_notification_revision, webforms_notification_dispatch, webforms_notification_attempt | A notification, its content, conditions, recipients and revisions; one queued send and one delivery attempt. |
webforms_confirmation, webforms_confirmation_content, webforms_confirmation_condition | A confirmation, its content and conditions. |
webforms_consent_event, webforms_terms_revision | A recorded consent; a revision of a terms document. |
Forms, sections and fields set no prefix of their own, so their saves fire only Magento's generic
core_abstract_* events. Use the form events above, or a plugin on the repository, to react to them.
Errors
What happens when an observer throws depends on where the event fires:
| Event | An exception in an observer |
|---|---|
webforms_result_save, webforms_result_delete | Ends the save or delete: the transaction is rolled back and the exception reaches the caller. |
webforms_validate_post_result | Ends the submission before it is saved. A LocalizedException is shown to the visitor as the error. To refuse a submission on purpose, add to errors instead of throwing. |
webforms_result_submit | The submission is already saved. A NoSuchEntityException is logged and ignored. Any other LocalizedException makes the call report failure with its message, though the submission stays stored. Other exceptions reach the caller. |
webforms_result_status_changed | The status change is already committed; Magento logs the exception as critical. |
webforms_result_status_mass_changed | Logged as a warning; the mass change still reports its result. |
webforms_builder_draft_activity | Ignored; the builder action still succeeds. |
| Every other event | Reaches the code that dispatched it, as with any Magento event. |
Bulk changes made directly in the database, such as the mass approval and mass status actions, don't save each
submission through its model: webforms_result_save and the webforms_result_save_* model events don't fire for
them. The dedicated events webforms_result_approve, webforms_result_status_changed and
webforms_result_status_mass_changed do.
Examples
Log every new submission. Declare the observer in etc/events.xml of your module so it runs for storefront,
admin and API submissions alike:
<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="urn:magento:framework:Event/etc/events.xsd">
<event name="webforms_result_submit">
<observer name="northstar_log_new_submission"
instance="Northstar\WebFormsLog\Observer\LogNewSubmission"/>
</event>
</config>
<?php
declare(strict_types=1);
namespace Northstar\WebFormsLog\Observer;
use MageMe\WebForms\Api\Data\ResultInterface;
use Magento\Framework\Event\Observer;
use Magento\Framework\Event\ObserverInterface;
use Psr\Log\LoggerInterface;
class LogNewSubmission implements ObserverInterface
{
private LoggerInterface $logger;
public function __construct(LoggerInterface $logger)
{
$this->logger = $logger;
}
public function execute(Observer $observer): void
{
if (!$observer->getData('is_new')) {
return;
}
/** @var ResultInterface $result */
$result = $observer->getData('result');
$this->logger->info('New WebForms submission', [
'result_id' => (int)$result->getId(),
'form_id' => (int)$result->getFormId(),
]);
}
}
Log ids, not answers: a submission often holds personal data. To send submissions to another service, use the queue described in Add-on integration contract rather than a call inside this observer.
To refuse a submission from webforms_validate_post_result, write the error list back:
$validate = $observer->getData('validate');
$errors = $validate->getData('errors') ?: [];
$errors[] = __('We deliver to addresses in Germany only.');
$validate->setData('errors', $errors);