Developer Events & Hooks

If you wish to extend the capabilities of Freeform, you can use any of the events and hooks below:

Events for Freeform Forms

  • onBeforeSubmit #
    • Called when a form is submitted, but before a submission model is being made
    • Contains these parameters:
      • form - the Form object
  • onAfterSubmit #
    • Called after saving the submission and saving the form
    • Contains these parameters:
      • form - the Form object
      • submission - the Freeform_SubmissionModel
  • onBeforeSave #
    • Called before saving a form
    • Contains these parameters:
      • model - the Freeform_FormModel
      • isNew - boolean value
  • onAfterSave #
    • Called after saving a form
    • Contains these parameters:
      • model - the Freeform_FormModel
      • isNew - boolean value
  • onBeforeDelete #
    • Called before deleting a form
    • Contains these parameters:
      • model - the Freeform_FormModel
  • onAfterDelete #
    • Called after deleting a form
    • Contains these parameters:
      • model - the Freeform_FormModel

Events for Freeform Submissions

  • onBeforeSave #
    • Called before saving a submission
    • Contains these parameters:
      • model - the Freeform_SubmissionModel
      • isNew - boolean value
  • onAfterSave #
    • Called after saving a submission
    • Contains these parameters:
      • model - the Freeform_SubmissionModel
      • isNew - boolean value
  • onBeforeDelete #
    • Called before deleting a submission
    • Contains these parameters:
      • model - the Freeform_SubmissionModel
  • onAfterDelete #
    • Called after deleting a submission
    • Contains these parameters:
      • model - the Freeform_SubmissionModel

Events for Freeform Fields

  • onBeforeSave #
    • Called before saving a field
    • Contains these parameters:
      • model - the Freeform_FieldModel
      • isNew - boolean value
  • onAfterSave #
    • Called after saving a field
    • Contains these parameters:
      • model - the Freeform_FieldModel
      • isNew - boolean value
  • onBeforeDelete #
    • Called before deleting a field
    • Contains these parameters:
      • model - the Freeform_FieldModel
  • onAfterDelete #
    • Called after deleting a field
    • Contains these parameters:
      • model - the Freeform_FieldModel

Events for Freeform Notifications

  • onBeforeSave #
    • Called before saving a notification
    • Contains these parameters:
      • model - the Freeform_NotificationModel
      • isNew - boolean value
  • onAfterSave #
    • Called after saving a notification
    • Contains these parameters:
      • model - the Freeform_NotificationModel
      • isNew - boolean value
  • onBeforeDelete #
    • Called before deleting a notification
    • Contains these parameters:
      • model - the Freeform_NotificationModel
  • onAfterDelete #
    • Called after deleting a notification
    • Contains these parameters:
      • model - the Freeform_NotificationModel

Events for Freeform Statuses

  • onBeforeSave #
    • Called before saving a status
    • Contains these parameters:
      • model - the Freeform_StatusModel
      • isNew - boolean value
  • onAfterSave #
    • Called after saving a status
    • Contains these parameters:
      • model - the Freeform_StatusModel
      • isNew - boolean value
  • onBeforeDelete #
    • Called before deleting a status
    • Contains these parameters:
      • model - the Freeform_StatusModel
  • onAfterDelete #
    • Called after deleting a status
    • Contains these parameters:
      • model - the Freeform_StatusModel

Events for Freeform File Uploads

  • onBeforeUpload #
    • Called before uploading a file
    • Contains these parameters:
      • field - the FileUploadField
      • form - the Form object
  • onAfterUpload #
    • Called after uploading a file
    • Contains these parameters:
      • field - the FileUploadField
      • assetId - boolean value
      • form - the Form object

Events for Freeform Mailing

  • onBeforeSend #
    • Called before sending an email
    • Contains these parameters:
      • model - the EmailModel
  • onAfterSend #
    • Called after sending an email
    • Contains these parameters:
      • model - the EmailModel
      • isSent - boolean value

Events for Freeform CRM Integrations

  • onBeforeSave #
    • Called before saving an integration
    • Contains these parameters:
      • model - the Freeform_IntegrationModel
      • isNew - boolean value
  • onAfterSave #
    • Called after saving an integration
    • Contains these parameters:
      • model - the Freeform_IntegrationModel
      • isNew - boolean value
  • onBeforeDelete #
    • Called before deleting an integration
    • Contains these parameters:
      • model - the Freeform_IntegrationModel
  • onAfterDelete #
    • Called after deleting an integration
    • Contains these parameters:
      • model - the Freeform_IntegrationModel

Events for Freeform Mailing-List Integrations

  • onBeforeSave #
    • Called before saving an integration
    • Contains these parameters:
      • model - the Freeform_IntegrationModel
      • isNew - boolean value
  • onAfterSave #
    • Called after saving an integration
    • Contains these parameters:
      • model - the Freeform_IntegrationModel
      • isNew - boolean value
  • onBeforeDelete #
    • Called before deleting an integration
    • Contains these parameters:
      • model - the Freeform_IntegrationModel
  • onAfterDelete #
    • Called after deleting an integration
    • Contains these parameters:
      • model - the Freeform_IntegrationModel

Usage instructions

In your plugin's ::init() method, subscribe to any of these events by using the craft()->on() method:

<?php

namespace Craft;

class YourPlugin extends BasePlugin
{
    public function init()
    {
        parent::init();

        // Forms
        craft()->on(
            "freeform_forms.onBeforeSave",
            function (Event $event) {
                $form = $event->params["model"];
                // Do something with this data
            }
        );

        // Submissions
        craft()->on(
            "freeform_submissions.onAfterSave",
            function (Event $event) {
                $submission = $event->params["model"];
                $isNew	  = $event->params["isNew"];
                // Do something with this data
            }
        );

        // Fields
        craft()->on(
            "freeform_fields.onBeforeDelete",
            function (Event $event) {
                $field = $event->params["model"];
                // Do something with this data
            }
        );

        // Notifications
        craft()->on(
            "freeform_notifications.onAfterDelete",
            function (Event $event) {
                $notification = $event->params["model"];
                // Do something with this data
            }
        );

        // Statuses
        craft()->on(
            "freeform_statuses.onBeforeSave",
            function (Event $event) {
                $status = $event->params["model"];
                // Do something with this data
            }
        );

        // File Uploads
        craft()->on(
            "freeform_files.onAfterUpload",
            function (Event $event) {
                $field   = $event->params["field"];
                $assetId = $event->params["assetId"];
                // Do something with this data
            }
        );

        // Mailing
        craft()->on(
            "freeform_mailer.onAfterSend",
            function (Event $event) {
                $model  = $event->params["model"];
                $isSent = $event->params["isSent"];
                // Do something with this data
            }
        );

        // CRM Integrations
        craft()->on(
            "freeform_crm.onBeforeSave",
            function (Event $event) {
                $crmIntegration = $event->params["model"];
                // Do something with this data
            }
        );

        // Mailing List Integrations
        craft()->on(
            "freeform_mailingLists.onBeforeSave",
            function (Event $event) {
                $mailingListIntegration = $event->params["model"];
                // Do something with this data
            }
        );
    }
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
Last Updated: 12/31/2018, 10:37:47 PM