Express Forms Express Forms for Craft
2.x Discontinued

WARNING

The Express Forms plugin has been discontinued. Please see the Freeform migration guide for more information.


Submission Events

If you wish to extend the capabilities of Submissions in Express Forms, feel free to use any of the events listed below:

Before Generating the Submission Title

The EVENT_BEFORE_BUILD_SUBMISSION_TITLE event is called when the submission title is about to be generated based on the Twig capable string in the Form Builder. You can use this event to attach additional data to the string or additional variables to the Twig environment. For example, you might want to add a UNIX Timestamp to all submissions.

use Solspace\ExpressForms\services\Submissions;
use Solspace\ExpressForms\events\submissions\BuildTitleEvent;

Event::on(
    Submissions::class,
    Submissions::EVENT_BEFORE_BUILD_SUBMISSION_TITLE,
    function (BuildTitleEvent $event) {
        // You could do a check to skip a specific form
        if ($event->getForm()->getHandle() === "some-specific-form") {
            return;
        }

        // We'll add a unix timestamp variable to the Twig environment
        // just as an example here.
        // This is an unnecessary extra step meant just for demonstrating the functionality
        $event->addTwigVariable('unix_timestamp', time());

        // Here, we modify the title that is about to be generated
        $event->setTitle($event->getTitle() . ' {{ unix_timestamp }}');
    }
);
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21

After the Submission has been Built

The EVENT_AFTER_BUILD_SUBMISSION event is called after the submission has been created based on the posted form data. Use this event to perform any modifications necessary.

WARNING

A submission object is built and populated regardless of your Save Submissions setting in the form. Some forms might never save the submission. For doing something with submissions which are about to be stored - use the Before Save Event.

use Solspace\ExpressForms\services\Submissions;
use Solspace\ExpressForms\events\submissions\BuildSubmissionEvent;

Event::on(
    Submissions::class,
    Submissions::EVENT_AFTER_BUILD_SUBMISSION,
    function (BuildSubmissionEvent $event) {
        $submisson  = $event->getSubmission();
        $postedData = $event->getPostedData();

        // Do something with the submission or anything else here
    }
);
1
2
3
4
5
6
7
8
9
10
11
12
13

Before the Submission is Saved

The EVENT_BEFORE_SAVE_SUBMISSION event is called before the submission is saved.

TIP

This event is cancelable, so you can prevent the submission from being saved.

WARNING

This event will only be called when saving Forms that have the Save Submissions setting set to true.

use Solspace\ExpressForms\services\Submissions;
use Solspace\ExpressForms\events\submissions\SaveSubmissionEvent;

Event::on(
    Submissions::class,
    Submissions::EVENT_BEFORE_SAVE_SUBMISSION,
    function (SaveSubmissionEvent $event) {
        // Do something with the submission or anything else here
        $submission = $event->getSubmission();
    }
);
1
2
3
4
5
6
7
8
9
10
11

After the Submission is Saved

The EVENT_AFTER_SAVE_SUBMISSION event is called after the submission is saved.

WARNING

This event will only be called when saving Forms that have the Save Submissions setting set to true.

use Solspace\ExpressForms\services\Submissions;
use Solspace\ExpressForms\events\submissions\SaveSubmissionEvent;

Event::on(
    Submissions::class,
    Submissions::EVENT_AFTER_SAVE_SUBMISSION,
    function (SaveSubmissionEvent $event) {
        $submission = $event->getSubmission();
        $form       = $event->getSubmission()->getForm();

        // Do something based on the submission data.
    }
);
1
2
3
4
5
6
7
8
9
10
11
12
13