Element Integration Events
If you have to perform any special checks or extra steps when validating or connecting Freeform submissions with Craft Elements, be sure to check out the events listed below:
Before an Element is validated
This event lets you add your own validations to the element validation process.
use Solspace\Freeform\Events\Integrations\ElementIntegrations\ValidateEvent;
use Solspace\Freeform\Library\Integrations\Types\Elements\ElementIntegrationInterface;
Event::on(
ElementIntegrationInterface::class,
ElementIntegrationInterface::EVENT_BEFORE_VALIDATE,
function (ValidateEvent $event) {
$form = $event->getForm();
$integration = $event->getIntegration();
$element = $event->getElement();
// Attach an error for the title field
// This example will always invalidate every connection
$element->addError('title', 'There are no good titles');
// This error will only show up in a freeform form
// if the attribute has been mapped to a form field.
}
);
After an Element is validated
use Solspace\Freeform\Events\Integrations\ElementIntegrations\ValidateEvent;
use Solspace\Freeform\Library\Integrations\Types\Elements\ElementIntegrationInterface;
Event::on(
ElementIntegrationInterface::class,
ElementIntegrationInterface::EVENT_AFTER_VALIDATE,
function (ValidateEvent $event) {
$form = $event->getForm();
$integration = $event->getIntegration();
$element = $event->getElement();
if (empty($element->getErrors())) {
// Do something if the element passes validation
}
}
);
Before an element is connected
This event is fired before the created and validated Element is saved.
use Solspace\Freeform\Events\Integrations\ElementIntegrations\ConnectEvent;
use Solspace\Freeform\Library\Integrations\Types\Elements\ElementIntegrationInterface;
Event::on(
ElementIntegrationInterface::class,
ElementIntegrationInterface::EVENT_BEFORE_CONNECT,
function (ConnectEvent $event) {
$form = $event->getForm();
$integration = $event->getIntegration();
$element = $event->getElement();
// Perform some actions here
}
);
After an element is connected
This event is fired before after the validated Element has been saved successfully.
use Solspace\Freeform\Events\Integrations\ElementIntegrations\ConnectEvent;
use Solspace\Freeform\Library\Integrations\Types\Elements\ElementIntegrationInterface;
Event::on(
ElementIntegrationInterface::class,
ElementIntegrationInterface::EVENT_BEFORE_CONNECT,
function (ConnectEvent $event) {
$form = $event->getForm();
$integration = $event->getIntegration();
$element = $event->getElement();
// Perform some actions here
}
);