Answers.Body: <p>If your Form has an Entries Relations field that identifies the Entry that you want to get a value from to send your email, you won't need a plugin at all and can target the email in the custom field on that entry. This can even be done for advanced fields such as Super Table as you have in your screenshot.</p>
  
  <p>In the case of the Super Table field in your screenshot, you could access the <code>emailOverride</code> value like so:</p>
  
  <pre><code>{{ object.relatedEntry.first().superTableField.emailOverride }}
  </code></pre>
  
  <p>If you wanted to be a bit more defensive, you could even add a conditional to check to make sure the value existed and fallback to another email adddress:</p>
  
  <pre><code>{{ object.relatedEntry.first().superTableField.emailOverride|length ? object.relatedEntry.first().superTableField.emailOverride : "fallback@email.com" }}
  </code></pre>
  
  <p>Note: In some cases, when looping or using conditionals your dynamic value in the recipients' field can get quite long. In older versions of Sprout Forms, the Notification Recipients value was stored as a VARCHAR field with 255 characters. If you happen to go over 255 characters in an older version of Sprout Forms, you will want to update to a more recent version of the plugin or update that database column to use the TEXT type to capture your full recipient value.</p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2018-08-07T01:59:19.770Z
Answers.LastActivityDate: 2018-08-07T01:59:19.770Z
Answers.UserDisplayName: Ben Parizek
Answers.Body: <p><em>Based on the event you are referencing, I believe this is a question about Sprout Forms for Craft 2. In Sprout Forms for Craft 3, notifications are handled a differently.</em></p>
  
  <p>In Sprout Forms for Craft 2, the event you'll want to use for this is the <code>SproutForms_OnBeforePopulateEntryEvent</code>.</p>
  
  <p>You're not able to modify which value gets set directly, so you'll have to swap in the value you want using Craft Object syntax.</p>
  
  <p>In your <code>notificationRecipients</code> field, add a value using Craft Object Syntax: <code>{myRecipientsEmail}</code>. Once you have called <code>sproutForms.onBeforePopulateEntryEvent</code> you can modify the $_POST data that gets processed when assigning the recipient value and it sure it has the value you want: <code>$_POST['myRecipientsEmail'] = 'so-and-so@website.com'</code> </p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2018-07-30T21:26:28.003Z
Answers.Text: Hi Ben. Thanks for the response. Sorry yes Craft 2. I'm missing something. I see in the event I can get the form (and the entry), so I can see notificationRecipients, and I can see that it's set to {myRecipientsEmail} - however setting the post data like that results in "Craft\SproutForms_EntryModel and its behaviors do not have a method or closure named "myRecipientsEmail".". How is setting the post data supposed to modify the *form* recipients rather than what tries to populate the *entry*? Thanks.
Answers.UserDisplayName: JamesNZ
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2018-07-30T21:32:49.300Z
Answers.Text: On the plus side, with your help for now I can update the $form->notificationRecipients and re-save it so at least functionally I can get where I need to be - but I'm curious about your answer.
Answers.UserDisplayName: JamesNZ
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2018-07-30T23:14:14.167Z
Answers.Text: Oh nope, updating that form was a bad idea. Setting the recipient and re-saving it destroyed all the form fields and tabs associated with it. Yikes. I'll wait to hear back then.
Answers.UserDisplayName: JamesNZ
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2018-07-31T03:15:05.700Z
Answers.Text: Can you drop us a note at sprout@barrelstrengthdesign.com with a copy of your db or at least a representative sample of what you are doing with forms? Sounds like something else is going on.
Answers.UserDisplayName: Ben Parizek
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2018-07-30T12:35:09.993Z
Answers.LastActivityDate: 2018-07-30T12:35:09.993Z
Answers.UserDisplayName: Ben Parizek
Body: <p>I've got an existing service based site that uses Sprout Forms to request quotes. The quote form lives on all services pages in a sidebar (and the submissions have an entries field keeping track of which service the submission came from).</p>
  
  <p>I've just added some fields into the services entry to allow them to override where the quote form goes.</p>
  
  <p><a href="https://i.sstatic.net/YIlXe.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/YIlXe.png" alt="enter image description here"></a></p>
  
  <p>Now I need to make this work. I have a plugin listening for <strong>sproutForms.onBeforeSaveEntry</strong> events, and when it receives them I'm wanting it to adjust where it sends the notification to.</p>
  
  <p>Is this possible? Is it possible to modify <strong>notificationRecipients</strong> on an individual event or is this against the form (and in either case how do I do this if I have a <strong>SproutForms_OnBeforeSaveEntryEvent</strong>)?</p>
  
  <p>In either case (as I can live with the former) a code example would be amazing.</p>
  
Tags: <plugin-development><plugin-sproutforms>
Title: Sprout Forms - Custom Form Notification Recipients With sproutForms.onBeforeSaveEntry
ThreadText: # Sprout Forms - Custom Form Notification Recipients With sproutForms.onBeforeSaveEntry
  
  (Asked by: username_0 on 2018-07-30)
  
  I've got an existing service based site that uses Sprout Forms to request quotes. The quote form lives on all services pages in a sidebar (and the submissions have an entries field keeping track of which service the submission came from).
  
  I've just added some fields into the services entry to allow them to override where the quote form goes.
  
  [![enter image description here](https://i.sstatic.net/YIlXe.png)](https://i.sstatic.net/YIlXe.png)
  
  Now I need to make this work. I have a plugin listening for **sproutForms.onBeforeSaveEntry** events, and when it receives them I'm wanting it to adjust where it sends the notification to.
  
  Is this possible? Is it possible to modify **notificationRecipients** on an individual event or is this against the form (and in either case how do I do this if I have a **SproutForms\_OnBeforeSaveEntryEvent**)?
  
  In either case (as I can live with the former) a code example would be amazing.
  
  **Tags:** plugin-development, plugin-sproutforms
  
  
  ---
  
  ## 2 answers
  
  ### Answer by username_1 on 2018-08-07. Score: 1 | Accepted answer
  
  If your Form has an Entries Relations field that identifies the Entry that you want to get a value from to send your email, you won't need a plugin at all and can target the email in the custom field on that entry. This can even be done for advanced fields such as Super Table as you have in your screenshot.
  
  In the case of the Super Table field in your screenshot, you could access the `emailOverride` value like so:
  
  ```
  {{ object.relatedEntry.first().superTableField.emailOverride }}
  
  ```
  
  If you wanted to be a bit more defensive, you could even add a conditional to check to make sure the value existed and fallback to another email adddress:
  
  ```
  {{ object.relatedEntry.first().superTableField.emailOverride|length ? object.relatedEntry.first().superTableField.emailOverride : "fallback@email.com" }}
  
  ```
  
  Note: In some cases, when looping or using conditionals your dynamic value in the recipients' field can get quite long. In older versions of Sprout Forms, the Notification Recipients value was stored as a VARCHAR field with 255 characters. If you happen to go over 255 characters in an older version of Sprout Forms, you will want to update to a more recent version of the plugin or update that database column to use the TEXT type to capture your full recipient value.
  
  
  ---
  
  ### Answer by username_1 on 2018-07-30. Score: 1
  
  *Based on the event you are referencing, I believe this is a question about Sprout Forms for Craft 2. In Sprout Forms for Craft 3, notifications are handled a differently.*
  
  In Sprout Forms for Craft 2, the event you'll want to use for this is the `SproutForms_OnBeforePopulateEntryEvent`.
  
  You're not able to modify which value gets set directly, so you'll have to swap in the value you want using Craft Object syntax.
  
  In your `notificationRecipients` field, add a value using Craft Object Syntax: `{myRecipientsEmail}`. Once you have called `sproutForms.onBeforePopulateEntryEvent` you can modify the $\_POST data that gets processed when assigning the recipient value and it sure it has the value you want: `$_POST['myRecipientsEmail'] = 'so-and-so@website.com'`
  
  > **Comments:**
  > **username_0**: Hi Ben. Thanks for the response. Sorry yes Craft 2. I'm missing something. I see in the event I can get the form (and the entry), so I can see notificationRecipients, and I can see that it's set to {myRecipientsEmail} - however setting the post data like that results in "Craft\SproutForms_EntryModel and its behaviors do not have a method or closure named "myRecipientsEmail".". How is setting the post data supposed to modify the *form* recipients rather than what tries to populate the *entry*? Thanks.  
  > **username_0**: On the plus side, with your help for now I can update the $form->notificationRecipients and re-save it so at least functionally I can get where I need to be - but I'm curious about your answer.  
  > **username_0**: Oh nope, updating that form was a bad idea. Setting the recipient and re-saving it destroyed all the form fields and tabs associated with it. Yikes. I'll wait to hear back then.  
  > **username_1**: Can you drop us a note at sprout@barrelstrengthdesign.com with a copy of your db or at least a representative sample of what you are doing with forms? Sounds like something else is going on.  
  
  ---
  
  