1

I'm newish to Craft CMS.

Im building a plugin for a client, one of their forms needs to post inputted data to an api then return a result to a hidden text area before the email if fired off.

I have built the form and plugin with event, only problem is this event fires with every form i have on the site now. is it possible to target a form handle in the event ?

Currently using

craft()->on('amForms_submissions.onBeforeSendEmail', function (Event $event) {
    $params = $event->params();
}

Thanks in advance

1

The following code fires the onBeforeEmailSubmission event (link)

// Fire an 'onBeforeEmailSubmission' event
$event = new Event($this, array(
    'email'      => $notificationEmail,
    'submission' => $submission,
));
$this->onBeforeEmailSubmission($event);

So you'll have access to the $submission and to the $email as array keys in your $params variable. In order to get the form you have to do

$submission = $params['submission'];
$form = $submission->getForm();
if($form->handle === 'whatever'){
     // do something
}
| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.