PLEASE NOTE: These forums are no longer utilized and are provided as an archive for informational purposes only. All support issues will be handled via email using our support ticket system. For more detailed information on this change, please see this blog post.

Dynamic population for contact form notifications

  1. mediaryte

    I have created a staff directory to manage the contact information of a company using custom post types. Using the list dynamic population snippet, I am able to populate a drop down menu for staff selection. I would like to use this list to create a contact form that sends the notification to the selected staff member.

    So here are my questions. Using a merge tag, can fill the notification's "Send To Email"? If so, what merge tag would I need to do this?

    If not, is it still possible to create the dynamic contact form and how?

    Thanks for the help!

    Posted 9 years ago on Thursday February 7, 2013 | Permalink
  2. mediaryte

    I was able to continue to edit the dynamic population snippet to include the email address as the value of the selection, however, this leaves the email address vulnerable and exposed. Perhaps there is another step I am missing to hide the email address?

    Posted 9 years ago on Friday February 8, 2013 | Permalink
  3. If the email address is stored in the custom post type, in a custom field, you can populate an admin only field in your form with that email address. I would add an email field to the form, and mark the visibility 'admin only'. Then, for the default value, use the merge tag {custom_field:your_meta_key}. That will pull the email address from the custom field into the email field, which is marked admin only.

    Then, in the notification, select this email field from the drop down to send the admin notification to.

    Does that work for you?

    Posted 9 years ago on Saturday February 9, 2013 | Permalink
  4. mediaryte

    Thank you for the help.

    I have tried adding {custom_field:email} as the default value of an admin only email field named Contact Email, but when testing the form I do not get a value returned for the email field. I have set the "Send To Email" from as {Contact Email:7}.

    Perhaps there is a disconnect between the populated contact list and the admin only email field?

    Posted 9 years ago on Saturday February 9, 2013 | Permalink
  5. Sounds like you did everything correctly. When you view the post in the post editor, where this form is embedded, can you view the custom fields and see that there is a custom field named "email" with an email address?

    If so, can you see if the entry contains that email address in field 7?

    Posted 9 years ago on Sunday February 10, 2013 | Permalink
  6. mediaryte

    I am embedding the form in a page, which may be the issue. I am not adding the form to the custom post type. The page contains only the form, with the populated contact list.

    The custom post type is 'contact' with a custom field name 'email'. I have the drop down list of the form populated with only the contacts that contain an email address ('email' returns TRUE).

    I set the contact email field to Everyone to view it in the form, however it does not display a value from the merge tag when selecting a contact from the drop down list. Source shows the value as empty.

    Posted 9 years ago on Sunday February 10, 2013 | Permalink
  7. What does this mean?

    with the populated contact list.

    How are you populating the drop down now? Can you share the code you're using for that?

    The merge tag {custom_field:email} will not work on a page that does not have a custom field with a meta key of "email".

    Posted 9 years ago on Sunday February 10, 2013 | Permalink
  8. mediaryte

    I am using the dynamic population code from the documentation - Dynamically Populating Drop Down Fields

    Posted 9 years ago on Monday February 11, 2013 | Permalink
  9. So you're dynamically populating the drop down with email addresses which are from a custom post type (contact) and stored in those posts in a meta key (custom field) of 'email'. Is that correct?

    The issue is you do not want the email address stored as the value for the drop down selection, since it would be visible in the source of the page?

    There is no easy way to do this without putting those values in the form somewhere when you gather them all from the custom posts (when you populate your drop down.) You need to use an email field to be able to use that address in the notification.

    You might need to pull the email addresses from the post again, based on the selection which was made. You could use the gform_pre_submission_filter and a function you write to pull the address from your custom post based on the selection which was made. I can't think of another way to do it in the form builder.

    Posted 9 years ago on Tuesday February 12, 2013 | Permalink
  10. mediaryte

    Ok, I follow you and yes to both of your questions.

    The function logic would be: A drop down of contacts with a value of the post ID. The contact post ID would be retrieved by the function and need to match the post ID (itself) of the listed emails created by the function. The function then returns the matched post ID's email for the notification "to" field and then returns the form complete, correct?

    Posted 9 years ago on Tuesday February 12, 2013 | Permalink
  11. I believe we're on the same page. Can you put some code together and give it a shot? If it does not work, post all the code at or and we'll have a look.

    Posted 9 years ago on Wednesday February 13, 2013 | Permalink
  12. mediaryte

    I have come far enough to make the function create a notification when using a static email inside the loop. However, once I try to use the input value, it does not return a value for 'to'.

    I have shared the code I am working with:

    Posted 9 years ago on Thursday February 14, 2013 | Permalink
  13. On line 14, can you see what the variable $to contains, to see if it is returning the email address correctly from your query? If that's not working, it has nothing to do with Gravity Forms but is an issue with using the WordPress functions.

    Posted 9 years ago on Monday February 18, 2013 | Permalink