Skip Navigation

[Resuelto] Contact Form: send an email notification using custom field from profile page

Este hilo está resuelto. Aquí tiene una descripción del problema y la solución.

Problem: I would like to send an email notification when a Form is submitted. The email address is stored as a custom field on the post where the Form is displayed.

Solution: Add a generic email field to your Form, hide it with CSS, and use the wpv-post-field shortcode to supply the default value like this:

<div style="display:none;">
[cred_generic_field field='hidden-email-address' type='email' class='' urlparam='']
{
"required":0,
"validate_format":0,
"persist":1,
"default":"[wpv-post-field name='wpcf-lawyer-email' id='$current_page']"
}
[/cred_generic_field]
</div>

Relevant Documentation:
https://toolset.com/documentation/user-guides/inserting-generic-fields-into-forms/

This support ticket is created hace 5 años, 7 meses. 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.

No supporters are available to work today on Toolset forum. Feel free to create tickets and we will handle it as soon as we are online. Thank you for your understanding.

Sun Mon Tue Wed Thu Fri Sat
8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 - -
13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 - -

Supporter timezone: America/New_York (GMT-04:00)

This topic contains 12 respuestas, has 3 mensajes.

Last updated by andresG-3 hace 5 años, 7 meses.

Assisted by: Christian Cox.

Autor
Mensajes
#1091474

Tell us what you are trying to do?

I´m developing a website with profile members page. Every profile page has a contact form to contact the professional.

1) I need to send a notification message dinamically to an e-mail custom field from profile member and a copy to info@ email

2) Also i need to set up properly an email notification to the guest user that fill the form. eg: Dear x, we received this message x...

Is there any documentation that you are following?

I´ve perform a google search and found some forum threads but with no succes

Is there a similar example that we can see?

What is the link to your site?

hidden link
(please keep it private)

#1091891

1. Usually in WordPress the Users will be a single entry and (should) be editable only by the Owner of the Profile.

2. That makes it difficult to trigger notifications based on Fields of the user, especially also, since you cannot connect Posts to users other than by authorship.

3. To solve this, proceed as follows:

- Create Users (and forms with which users can either register and/or edit their Profile)
- These Forms are all only accessible to the Users them selves, and they do hold all the data a Professional needs to add about him/herself
- Then, double the Users to a Post Type "professionals" as outlined here:
https://toolset.com/documentation/user-guides/how-to-create-custom-searches-and-relationships-for-users/
- After, create a new Post Type "contacts" or "Messages", or similar.
- This post type has all fields you need a guest to submit when the guest contacts a professional.
- Create a one to many relationship where Professional is one, and Messages many.
- Create a Post Form for Messages and bind a notification to this form.
==> This notification is sent to an email specified in the form field. The form field must be completed by the submitter with she/her (guest) email.
- In the same form, populate another Field, with the Email of the professional.
==> This email is stored in the parent post "Professional". To get it's value, you can follow these steps:
https://toolset.com/forums/topic/displaying-data-from-parent-post-type-in-cred-form/#post-602522
It will return you the ID of the parent post, which can be used to get the Field value (email) of that post.
- Now add another notification to this form that is sent to the Professional.

This form then is used as a "Create Child post Link" (as Luo explains in above linked post) and inserted (the link to the form) on "Professional" posts.
Clicked they will lead to the form that creates Child Messages and the guest can fill that out + submit, which will then trigger the notification - and of course save a child post to the Professional, which can be used as well for further "communication".

However, after this lightly complex steps, you perhaps feel this is not the right way.
The problem is, Toolset is not a tool to build "messaging systems".

It is possible, yes, but it's not what's it designed for.
The Forms and notifications are intended as a Content Create/Edit tool that lets you fire notifications (not messages) on certain events.

For full messaging features, things like BuddyPress or WP Symposium PRO are much more advanced.

#1092024
case-02-profile-lawyer-page.jpg
case-01-contact-us.jpg

Ok Beda, im going to try to explain me better. If you don't understand something please let me know, i speak spanish and english is not my first language.

First of all the purpouse of this law firm institutional web site is only to showcase a list of lawyers profiles and show their experience and a simple contact form to reach on their specific page.

This website is not pretending to be a community system like Buddypress with a strong message system. There would be only one user admin from the firm that is going to be in charge to add, modify or delete profiles, see web lead messages, etc.

I guess that the requirement it's more simple than you explained in previously answer. I´m going to tell what i´ve done so far in detail to see if im on the right track to make this happen.

Case 01

I´ve created a contact-us page with a public post form submission for custom post type "Messages"

This form sends two notifications: one to an specific and generic email like webmaster@ or info@ and the other to the e-mail`s guest/visitor.

This case is working correctly at my website. The same form from contact-us is inserted below every lawyer profile page using the same 2 notification alerts.

But my goal is to achieve this scenario >>>

Case 02

There is a custom post type called "Profiles" that have some custom fields like

- Place of birth
- Practice areas
- Experience details
- Lawyer E-mail

and also there is custom post type "Messages" that work at public frontend with some fields.

- Subject title (wp field from post type)
- Name and last name
- Lead E-mail
- Message
- Captcha

The visitors can send a message to ask a question to an specific lawyer. Right now this form is the same present in contact us page.

I need to send a 3rd notification "new message submission from domain.com" but for the lawyer´s specific e-mail address. This info is saved in the custom field "Lawyer E-mail "

The all purpouse of this form is to avoid to public the personal e-mail address of the lawyer because of privacy and SPAM issues.

How can i pass the e-mail address from lawyer profile custom field to an alert notification created in the Post form "Send us a message"? there is something similar to use an specfial custom field shortcode? thanks in advance

#1092386

Hi, on a Lawyer profile post you can display custom field values from the current page using the $current_page operator, like this:

[wpv-post-field name='wpcf-lawyer-email' id='$current_page']

If you want to send an email to that custom field email address, you can pass the value into a Forms generic hidden field. Use the "Add generic field" button above the Form editor panel to insert a hidden field shortcode. Then add the email address to the hidden field value, and add the "persist" attribute like this:

[cred_generic_field field='hidden-email-address' type='hidden' class='' urlparam='']
{
"required":0,
"validate_format":0,
"persist":1,
"default":"[wpv-post-field name='wpcf-lawyer-email' id='$current_page']"
}
[/cred_generic_field]

Then edit your email notification and choose the "hidden-email-address" field as the "to" address. You may have to click the refresh icon to see the generic field appear as an option.

If this approach is not acceptable for privacy reasons, then you can use the Forms API to programmatically change the notification recipients.
https://toolset.com/documentation/programmer-reference/cred-api/#cred_notification_recipients

In this case, you will add a generic hidden field that contains the current Lawyer's post ID instead of the email address. Then in the API hook, you can get the custom field value using that post ID and use it to set the "To:" address. Let me know if you have additional questions about that.

#1092458
Edit Post Form ‹ e-mail hidden field - renders in front end 02.png
Edit Post Form ‹ e-mail hidden field - renders in front end 01.png

Christian! thanks for your help! I Think that we are getting closer to the solution. That´s the idea I have on my mind.

I´ve follow your steps. For some reason Beaver builder theme renders the code on public frontend (see printscreens attached for reference)

I have added the code to the post form edit area. I need to place this code in another place?

I think that the code is working ok because i can see rendering the specific e-mail custom field from lawyer profile.

Please let me know what i´m doing wrong. Perhaps it`s better if you take a look for yourself at wp-admin.

Refer to the user and password i´ve sent you on my other issue. Thanks in advance!

#1092470

The code looks okay, but it should be inside the credform shortcode. It won't be rendered correctly outside the credform shortcodes. Try that and if it still does not work I'll take a closer look.

#1092471

Christian, where i can find "inside the credform shortcode"

#1092472
inside.png

You can find it inside the Form editor.

#1092477
where-to-add-hidden-field.jpg

Ok i place the code where you mentioned, and now is hidden.

I refresh the notification select menu in order to find the new e-mail variable to add in TO: field but nothing happens.

THIS STEP >
"Then edit your email notification and choose the "hidden-email-address" field as the "to" address. You may have to click the refresh icon to see the generic field appear as an option."

It works if the variable is included in "send to an specific email address" as some kind of shortcode?^

#1093074

Okay I see the issue, sorry. Please change the type of generic field to "email" instead of "hidden". Then wrap the field in a div that is hidden with CSS, like this:

<div style="display:none;">
[cred_generic_field field='hidden-email-address' type='email' class='' urlparam='']
{
"required":0,
"validate_format":0,
"persist":1,
"default":"[wpv-post-field name='wpcf-lawyer-email' id='$current_page']"
}
[/cred_generic_field]
</div>

Save the Form and refresh the page, and you should then be able to find the generic field in the email recipients select field.

#1093132

Thanks Christian!

Now i can select the hidden-email-adress variable and it works! thanks for your help. There is an small detail that i want to achieve and is to use on subject email notification wp-title from profile page "lawyer name a last name" but it seems that is loading this from wp-title of form "name and last name"

Subject notification example
[wpv-post-title] you have a new message from your profile page

New threads created by Christian Cox and linked to this one are listed below:

https://toolset.com/es/forums/topic/forms-add-current-page-information-to-email-notification-subject/

#1093208

That sounds like a different task, so I have split it off into another ticket.

#1097421

thanks!

This ticket is now closed. If you're a WPML client and need related help, please open a new support ticket.