Implementing a status dependent submission-to-entry workflow #2253
Unanswered
michaelhue
asked this question in
Q&A
Replies: 1 comment 4 replies
-
I had some success implementing this with event listeners. First we want to ensure that the element integration with the handle Event::on(
Entry::class,
Entry::EVENT_BEFORE_SEND_PAYLOAD,
function (SendIntegrationPayloadEvent $event): void {
// Do nothing if this is not the target integration.
if ($event->integration->getHandle() !== 'entry') {
return;
}
// Always prevent the integration from running if the submission
// does not have the correct status.
if ($event->submission->getStatus() !== 'accepted') {
$event->isValid = false;
}
}
); With this condition in place, we can now manually trigger the Event::on(
Submission::class,
Submission::EVENT_AFTER_SAVE,
function (ModelEvent $event): void {
/** @var Submission */
$submission = $event->sender;
// Ignore incomplete/spam submissions.
if ($submission->isIncomplete || $submission->isSpam) {
return;
}
$integrations = Formie::$plugin->getIntegrations()
->getAllEnabledIntegrationsForForm($submission->getForm());
// Find the target integration.
$integration = ArrayHelper::firstWhere(
$integrations,
fn(Integration $i) => $i->getHandle() === 'entry'
);
// Do nothing if the target integration is disabled/missing.
if (!$integration) {
return;
}
Formie::$plugin->getSubmissions()
->sendIntegrationPayload($integration, $submission);
}
); Note that the There is currently a bug that prevents this setting from working correctly though: |
Beta Was this translation helpful? Give feedback.
4 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
I'm using Formie in a few projects, primarily as a way for site users to submit entries without access to the control panel. This is achieved with the
Element
integration and mostly works, but the backend experience could be improved.My ideal workflow would look like this:
New
, but no entry is created (yet).Accepted
and saves the form.Rejected
. No entry will be created.So my main problem with the current state of the plugin is the
Element
integration triggering on the initial form submission (before it can be checked).I would love a setting that triggers the integration every time a submission is saved, but only if it has a specific status.
Does anyone have an idea how to achieve this? My intuition would be to build a custom integration on top of the
Element
integration and change the conditions that trigger it, but I'm not sure if that is possible at all.Thanks!
Beta Was this translation helpful? Give feedback.
All reactions