Answers.Body: <p>This can be done using an Invisible Field and the <code>addFieldVariables</code> tag.  Define the value you want as your email in your template:</p>
  
  <pre><code>{% do craft.sproutForms.addFieldVariables({
      'secretEmailAddress': entry.author.email
  }) %}
  </code></pre>
  
  <p>Set the Invisible Field to target that value:</p>
  
  <pre><code>{secretEmailAddress}
  </code></pre>
  
  <p>And then customize the Notification Email Recipients field to target the handle of the Invisible Field:</p>
  
  <pre><code>{invisibleFieldHandle}
  </code></pre>
  
  <p>Another example of doing this dynamically from an Entry with a Form Relations field has been posted in response to another question here: <a href="https://craftcms.stackexchange.com/a/29553/115">https://craftcms.stackexchange.com/a/29553/115</a></p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2019-02-19T14:45:29.590Z
Answers.LastActivityDate: 2019-02-19T14:45:29.590Z
Answers.UserDisplayName: Ben Parizek
Body: <p>I am including a sprout form on my template like this:</p>
  
  <pre><code>...
  {{ craft.sproutForms.displayForm('myForm') }}
  ...
  </code></pre>
  
  <p>I am submitting the form via ajax, and when the form is submitted I am trying to set the recipient in Sprout Email to the form's container author.</p>
  
  <pre><code>{author.email}
  </code></pre>
  
  <p>So it's not the author of the submitted form/entry, it's the author of the entry that the form is sitting on that I'm trying to access.</p>
  
  <p>I'd really like to avoid passing in an email from a hidden input if at all possible. Thank you for any suggestions!</p>
  
  <p><strong>Update</strong></p>
  
  <p>For example, I am on the page <code>a.html</code> which  has an author of <code>damon@email.com</code>. On <code>a.html</code> there is a contact form. When a user submits the contact form, I want a confirmation email sent tothem, and then an email sent to the author of the entry that the contact form is on. The same contact form can live on any page, and each page could have different authors.</p>
  
  <p><code>a.html</code> has an author of <code>damon@email.com</code>
  <code>b.html</code> has an author of <code>foo@email.com</code></p>
  
  <p>In the above case, a confirmation email needs to go whomever filled out the form, and then a notification email to each of the entries respectively.</p>
  
  <p><strong>Update 2</strong></p>
  
  <p>I am getting closer I think, but struggling to dynamically set the recipient.</p>
  
  <p>Here is my form:</p>
  
  <pre><code>...
  {% set form = craft.sproutForms.form('myForm') %}
  &lt;input type="hidden" name="action" value="sproutForms/entries/saveEntry"&gt;
  &lt;input type="hidden" name="handle" value="{{ form.handle }}"&gt;
  &lt;input type="hidden" name="entry" value="{{ entry.id }}"&gt;
  &lt;input type="hidden" name="author" value="{{ entry.author.id }}"&gt;
  </code></pre>
  
  <p>Then in my plugin I am doing this:</p>
  
  <pre><code>craft()-&gt;on('sproutForms.onBeforeSaveEntry', function (Event $event) {
      if (craft()-&gt;request-&gt;isSiteRequest()) {
          if (craft()-&gt;request-&gt;getPost('author') != '') {
              $owner = craft()-&gt;users-&gt;getUserById(craft()-&gt;request-&gt;getPost('author'));
  
              if ($owner) {
                  if ($event-&gt;params['isNewEntry']) {
                      $entry = $event-&gt;params['entry'];
  
                      $entry-&gt;setContentFromPost(array(
                          'ownerEmail' =&gt; $owner-&gt;email, // damon@email.com
                      ));
  
                     // Set {ownerEmail} as recipient in notification?
                  }
              }
  </code></pre>
  
  <p>In my ajax response I am seeing:</p>
  
  <pre><code>{"errors":[]}
  </code></pre>
  
  <p>In the <code>sproutemail.log</code> I am seeing:</p>
  
  <pre><code>[error] [plugin] No recipients found.
  </code></pre>
  
  <p>In the recipient field I have tried <code>{ownerEmail}</code> and <code>{object.ownerEmail}</code> both having no success.</p>
  
  <p>I have also tried setting field values just in the off chance...</p>
  
  <pre><code>{% do craft.sproutForms.addFieldVariables({ entry: entry }) %}
  </code></pre>
  
  <p>The whole purpose of this is that I am trying to avoid putting a person's email in a hidden input. Just so that if a user of the site viewed the source the author's email wasn't right out in the open.</p>
  
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2017-03-29T12:43:12.433Z
Comments.Text: When you say "form's container author" are you referring to an author of a Channel Entry where the form is displaying on the same page?  If that's the case, I can respond in more detail but the EntryModel is not going to be available to use as a dynamic recipient unless you explicitly make it available using a form field and something like Sprout Fields Invisible, Hidden, or Email Select fields.
Comments.UserDisplayName: Ben Parizek
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2017-03-29T13:55:40.913Z
Comments.Text: Hi Ben - you are right. I have updated my question with a bit more detail.
Comments.UserDisplayName: Damon
Tags: <plugin-development><plugin-sproutforms><plugin-sproutemail>
Title: How can I get the parent author from sprout forms to send to sprout mail?
ThreadText: # How can I get the parent author from sprout forms to send to sprout mail?
  
  (Asked by: username_0 on 2017-03-29)
  
  I am including a sprout form on my template like this:
  
  ```
  ...
  {{ craft.sproutForms.displayForm('myForm') }}
  ...
  
  ```
  
  I am submitting the form via ajax, and when the form is submitted I am trying to set the recipient in Sprout Email to the form's container author.
  
  ```
  {author.email}
  
  ```
  
  So it's not the author of the submitted form/entry, it's the author of the entry that the form is sitting on that I'm trying to access.
  
  I'd really like to avoid passing in an email from a hidden input if at all possible. Thank you for any suggestions!
  
  **Update**
  
  For example, I am on the page `a.html` which has an author of `username_0@email.com`. On `a.html` there is a contact form. When a user submits the contact form, I want a confirmation email sent tothem, and then an email sent to the author of the entry that the contact form is on. The same contact form can live on any page, and each page could have different authors.
  
  `a.html` has an author of `username_0@email.com`
  `b.html` has an author of `foo@email.com`
  
  In the above case, a confirmation email needs to go whomever filled out the form, and then a notification email to each of the entries respectively.
  
  **Update 2**
  
  I am getting closer I think, but struggling to dynamically set the recipient.
  
  Here is my form:
  
  ```
  ...
  {% set form = craft.sproutForms.form('myForm') %}
  <input type="hidden" name="action" value="sproutForms/entries/saveEntry">
  <input type="hidden" name="handle" value="{{ form.handle }}">
  <input type="hidden" name="entry" value="{{ entry.id }}">
  <input type="hidden" name="author" value="{{ entry.author.id }}">
  
  ```
  
  Then in my plugin I am doing this:
  
  ```
  craft()->on('sproutForms.onBeforeSaveEntry', function (Event $event) {
      if (craft()->request->isSiteRequest()) {
          if (craft()->request->getPost('author') != '') {
              $owner = craft()->users->getUserById(craft()->request->getPost('author'));
  
              if ($owner) {
                  if ($event->params['isNewEntry']) {
                      $entry = $event->params['entry'];
  
                      $entry->setContentFromPost(array(
                          'ownerEmail' => $owner->email, // username_0@email.com
                      ));
  
                     // Set {ownerEmail} as recipient in notification?
                  }
              }
  
  ```
  
  In my ajax response I am seeing:
  
  ```
  {"errors":[]}
  
  ```
  
  In the `sproutemail.log` I am seeing:
  
  ```
  [error] [plugin] No recipients found.
  
  ```
  
  In the recipient field I have tried `{ownerEmail}` and `{object.ownerEmail}` both having no success.
  
  I have also tried setting field values just in the off chance...
  
  ```
  {% do craft.sproutForms.addFieldVariables({ entry: entry }) %}
  
  ```
  
  The whole purpose of this is that I am trying to avoid putting a person's email in a hidden input. Just so that if a user of the site viewed the source the author's email wasn't right out in the open.
  
  **Tags:** plugin-development, plugin-sproutforms, plugin-sproutemail
  
  > **Comments:**
  > **username_1**: When you say "form's container author" are you referring to an author of a Channel Entry where the form is displaying on the same page?  If that's the case, I can respond in more detail but the EntryModel is not going to be available to use as a dynamic recipient unless you explicitly make it available using a form field and something like Sprout Fields Invisible, Hidden, or Email Select fields.  
  > **username_0**: Hi Ben - you are right. I have updated my question with a bit more detail.  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_1 on 2019-02-19. Score: 1
  
  This can be done using an Invisible Field and the `addFieldVariables` tag. Define the value you want as your email in your template:
  
  ```
  {% do craft.sproutForms.addFieldVariables({
      'secretEmailAddress': entry.author.email
  }) %}
  
  ```
  
  Set the Invisible Field to target that value:
  
  ```
  {secretEmailAddress}
  
  ```
  
  And then customize the Notification Email Recipients field to target the handle of the Invisible Field:
  
  ```
  {invisibleFieldHandle}
  
  ```
  
  Another example of doing this dynamically from an Entry with a Form Relations field has been posted in response to another question here: <https://craftcms.stackexchange.com/a/29553/115>
  
  
  ---
  
  