Skip Navigation

[Resolved] Email not sent to post author when form is submitted

This thread is resolved. Here is a description of the problem and solution.

Problem:

The issue here is that the user has a child form on a parent page but wants to send an email to the parent post author when the form is submitted
Solution:
The solution for this can be seen below.
https://toolset.com/forums/topic/email-not-sent-to-post-author-when-form-is-submitted/#post-1184225

This support ticket is created 6 years ago. There's a good chance that you are reading advice that it now obsolete.

This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.

Sun Mon Tue Wed Thu Fri Sat
- 9:00 – 12:00 9:00 – 12:00 9:00 – 12:00 9:00 – 12:00 9:00 – 12:00 -
- 13:00 – 18:00 13:00 – 18:00 13:00 – 18:00 14:00 – 18:00 13:00 – 18:00 -

Supporter timezone: America/Jamaica (GMT-05:00)

This topic contains 4 replies, has 3 voices.

Last updated by philipM-3 6 years ago.

Assisted by: Shane.

Author
Posts
#1182482
Example post with form.PNG
User for example post.PNG
Email Log.PNG
Edit Post Form Send Notification Settings.PNG
Post Form Settings.PNG

I am trying to: Submit the form details a volunteer opportunity enquiry to the organisation (post author)

Link to a page where the issue can be seen: hidden link

I expected to see: An email sent to the author of the post when the form is completed.

Instead, I got: No email sent to them even though settings in post forms has the send notification to author.

See attached screenshots to show the settings for each section and email log.

Many thanks

Philip

#1182777

1. No email sent to them even though settings in post forms has the send notification to author

When you set a form to send the email to the author it will send the email to the author of the post that is either created or edited with that precise form, not to the author of the container, where you put the form into.

2. To send an email to the author of the Post where you insert the Form to (container), you will need custom code.
You could, for example, update a Custom Field in the form (it can be hidden, but persisting field) with the email of the author of the container where you put the Form into.
Then set the notification to be sent to that field's email

Most likely, but I am not sure, you want to send the email to the author of the Post "Volunteer Opportunity" and not to the author of the "Volunteer Enquiry", which is what you are creating/editing with the forms in question.

Hence you would need to use the cred_save_data hook to add some custom code which:
- gets the current container author
- gets their email
- puts that in a new field you added before to Types, then to the Form with Toolset Forms (single line for example)
- after, the email notification is set to send to that field email value

cred_save_data is a hook that will fire your code a the moment of saving the data on the database:
https://toolset.com/documentation/programmer-reference/cred-api/#cred_save_data
It delivers as well a container_id, which is the ID of the post where you insert this form to, and that should be the post you want the author's email of, so to send them a notification.
Hence, you can use $form_data['container_id'] to get the Post ID of the container and then the email of that author. You will use get_post_field(), the_author_meta():
https://codex.wordpress.org/Template_Tags/the_author_meta
https://codex.wordpress.org/Function_Reference/get_post_field

Please let me know if you are not familiar with Custom Code - I could give an example.
You can already find a large set of these here:
hidden link
https://pastebin.com/u/bedas
https://toolset.com/documentation/adding-custom-code/using-toolset-to-add-custom-code/
https://toolset.com/documentation/adding-custom-code/

#1184210

Hi,

Thanks for your reply and guidance.

Please could you provide an example and where I should put the code?

Many thanks

Philip

#1184225

Shane
Supporter

Languages: English (English )

Timezone: America/Jamaica (GMT-05:00)

Hi Philip,

I took a look at this for you.

A simpler solution is possible since the form is actually on the listing page.

You can get the email from the author by doing this.

    
<div class="hidden">
[cred_generic_field type='email' field='hidden_author_email']
{
"required":0,
"persist":1,
"validate_format":0,
"default":"[wpv-post-author format='meta' meta='user_email']"
}
[/cred_generic_field]
</div>

Adding that generic field to your form and it will get the author email. Now to hide this from display you need to use this css.

.hidden{
display:none;
}

Finally all you need to do is to set your notification to "Send notification to an email specified in an email field included in the form"

Then just select this email field.

Once you have done this then it should send the notification to the author.

Please let me know if this helps.
Thanks,
Shane

#1184378

My issue is resolved now. Thank you!