Answers.Body: <p>The following code fires the onBeforeEmailSubmission event (<a href="https://github.com/am-impact/amforms/blob/master/services/AmForms_SubmissionsService.php#L351" rel="nofollow noreferrer">link)</a></p>
  
  <pre><code>// Fire an 'onBeforeEmailSubmission' event
  $event = new Event($this, array(
      'email'      =&gt; $notificationEmail,
      'submission' =&gt; $submission,
  ));
  $this-&gt;onBeforeEmailSubmission($event);
  </code></pre>
  
  <p>So you'll have access to the <code>$submission</code> and to the <code>$email</code> as array keys in your <code>$params</code> variable. In order to get the form you have to <a href="https://github.com/am-impact/amforms/blob/master/models/AmForms_SubmissionModel.php#L65" rel="nofollow noreferrer">do</a> </p>
  
  <pre><code>$submission = $params['submission'];
  $form = $submission-&gt;getForm();
  if($form-&gt;handle === 'whatever'){
       // do something
  }
  </code></pre>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2018-01-12T05:42:50.697Z
Answers.LastActivityDate: 2018-01-12T05:42:50.697Z
Answers.UserDisplayName: Robin Schambach
Body: <p>I'm newish to Craft CMS.</p>
  
  <p>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.</p>
  
  <p>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 ?</p>
  
  <p>Currently using </p>
  
  <pre><code>craft()-&gt;on('amForms_submissions.onBeforeSendEmail', function (Event $event) {
      $params = $event-&gt;params();
  }
  </code></pre>
  
  <p>Thanks in advance</p>
  
Tags: <plugin-development><plugin-amforms>
Title: Craft Form Event - Target a Single Form
ThreadText: # Craft Form Event - Target a Single Form
  
  (Asked by: username_0 on 2018-01-11)
  
  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
  
  **Tags:** plugin-development, plugin-amforms
  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_1 on 2018-01-12. Score: 1
  
  The following code fires the onBeforeEmailSubmission event ([link)](https://github.com/am-impact/amforms/blob/master/services/AmForms_SubmissionsService.php#L351)
  
  ```
  // 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](https://github.com/am-impact/amforms/blob/master/models/AmForms_SubmissionModel.php#L65)
  
  ```
  $submission = $params['submission'];
  $form = $submission->getForm();
  if($form->handle === 'whatever'){
       // do something
  }
  
  ```
  
  
  ---
  
  