Skip Navigation

[Resolved] Email Notification Upon Form Submission with no inputs for Member site

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

Problem:
Can CRED send a Email to the author of the Post where the CRED form is inserted to (not the post edited) with the data of the user clicking/submitting the form?

Solution:
Create a Cred Form that holds only one generic Form Field (see below), and the Submit Button and the mandatory CRED Fields.

The CRED Form must hold a Generic Field, hidden, of type email.
You can hide it with

The Form creates a Post of Type "your-choice"
Do not include a Title Field, or somehow with CRED API populate this Title with a value, or CRED will create a AutoGenerated Draft.

Add a Notification to the CRED form that "Sends notification to an email specified in a form field:
"above created CRED generic Hidden Field"

Apply a

cred_save_data

action to the CRED Form, which grabs the Email of the author of the Post wher you insert the CRED form.
To access this Post Object, you use

$form_data['container_id']

(to get the data of the Post where the CRED is inserted to.)

You get it's author and then that authors Email.
This is done with WordPress API.

Then, once you have above infos, you update your CRED Generic Field with the

update_post_meta

function (still in your CRED

cred_save_data

function)

Then submitting the form will send the email to the author of the post wher the CRED is inserted to.

Relevant Documentation:
https://toolset.com/documentation/user-guides/creating-cred-forms/
http://codex.wordpress.org/Function_Reference/get_post_field
https://codex.wordpress.org/Function_Reference/get_userdata

This support ticket is created 6 years, 9 months 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
- - 14:00 – 20:00 14:00 – 20:00 14:00 – 20:00 14:00 – 20:00 14:00 – 20:00
- - - - - - -

Supporter timezone: Asia/Ho_Chi_Minh (GMT+07:00)

This topic contains 4 replies, has 2 voices.

Last updated by sheaN 6 years, 8 months ago.

Assigned support staff: Beda.

Author
Posts
#395794

Ok I have non-typical request here. I have a membership site and basically people can register to post deals on their products to the site. Users can then browse the deals and then hit a "Claim" button on the deal posted by another user. This would then send an email to the user that posted that deal saying someone was interested in the deal here is their user name and contact info which should be dynamically pulled from their user data they entered when they registered for the site.

So can CRED submit a blank form (form with no inputs, but just a submit button labled "Claim") that would then pull the user who submitted the forms data to be able to send that data in an email notification to the owner of the post?

#396066

Yes, this should be possible.

1. Create a Cred Form that holds only one generic Form Field (see below), and the Submit Button and the mandatory CRED Fields.
https://toolset.com/documentation/user-guides/creating-cred-forms/

2. The CRED Form must hold a Generic Field, hidden, of type email.
You can hide it with <div class="hidden">field here</div>

2. The Form shall create a Post of Type "your-choice"
Be aware that if you do not include a Title Field, or somehow with CRED API populate this Title with a value, CRED will create a AutoGenerated Draft

3. Add a Notification to the CRED form that "Sends notification to an email specified in a form field:"
The Form Field shall be the above created CRED generic Hidden Field.

4. Apply a cred_save_data action to the CRED Form, which will grab the Email of the User that authored the "Post" which the current user is claiming with this form.

Keep in mind that you will need to use the CRED API

$form_data['container_id']

to get the data of the Post which is being claimed.

Once you have the Post Object (which is being claimed), you get it's author and then that authors Email.
This is done with WordPress API:
http://codex.wordpress.org/Function_Reference/get_post_field
https://codex.wordpress.org/Function_Reference/get_userdata

Then, once you have above infos, you update your CRED Generic Field with the update_post_meta function (still in your CRED cred_save_data function)

This will work if the CRED form is inserted in a SINGLE post which has to be claimed.

Thank you

#396603

Hi Beda, thanks for your response.

I am familiar with how to create CRED forms but have not done much with the API. Is this cred_save_data action supposed to go in the JS box on the edit CRED screen?

Also you mention at the end that this will work IF the for is inserted in the SINGLE post. What if it is inserted on an item in a list like search results? So I get a list of 10 results and each has a "Claim" button on it, are you saying this will only work if it is in a single post and not in a loop with other posts?

#396793

1. I am familiar with how to create CRED forms but have not done much with the API. Is this cred_save_data action supposed to go in the JS box on the edit CRED screen?

In the functions.php of your Custom or Child theme
This is PHP Code and PHP code always needs to go to your Theme's or Plugins Files, and never in a WP Admin area editor.

2. Also you mention at the end that this will work IF the for is inserted in the SINGLE post.

Yes, this because we will work with

$form_data['container_id']

This will return the ID of the Post / Page in where the CRED Form is inserted.
So if you have a list of posts and each will have a CRED form, the container_id still will be the Page / Post in where the List is inserted to.

3. So I get a list of 10 results and each has a "Claim" button on it

This is also possible but then you will need to get the Current Posts Author Email by accessing the Current (in Loop) Post's Object, and extract the author's info from it.

You could also set the Notification to be sent to a Email specified in a Form Field (still generic Field) and try to populate this Field with the ShortCode "wpv-post-author"
https://toolset.com/documentation/views-shortcodes/#wpv-post-author

The Generic Field in CRED would be hidden as well with the Hidden DIV class.

I am not sure this will work, as it is a nested ShortCode and CRED does basically not support nested ShortCodes in some cases, as it's not suggested by WordPress.
Only Views provides methods to nest ShortCodes or use ShortCodes to populate HTML.
(Still, WordPress is actually not suggesting this usage of ShortCodes)

Please let me know if you need more info in regard.

#398854

Ok I got this all worked out. I did end up using a shortcode in the generic CRED field and it works just fine. Thanks for the suggestion, perhaps this situation can be supported in the future.