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 damon@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 damon@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, // damon@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.