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.

Contact form - populated email

  1. I've created a campus employee directory using custom fields and would very much like to put a simple contact form in the template that will populate the TO email addy based on the content of the email_value field. It would essentially be a hidden field.

    This would allow me to add a simple form to the template file that would display on each employee and allow our visitors to contact the appropriate faculty/staff member directly from their directory listing.

    Possible?

    Posted 10 years ago on Tuesday January 12, 2010 | Permalink
  2. Also, it just occurred to me that some of our employees don't have email. I'd very much like for the form to not show up in those cases.

    Posted 10 years ago on Tuesday January 12, 2010 | Permalink
  3. Hey Shelley,

    What you can do is create a custom page template that only displays the contact form if the email_value field has a value. You would need to display the form using the function call. So if email_value exists then display the form.

    You can override the notification email TO field using a hook. You can read how another user (Jan Egbert) has accomplished this here:

    http://forum.gravityhelp.com/topic/sending-form-to-author-of-post

    In his example he is routing the notification to the author of the post.

    Posted 10 years ago on Tuesday January 12, 2010 | Permalink
  4. Carl,

    In respect to that very thread in which Jan replied, I need a little guidance on where I should be placing the filters. I've tried putting them in the theme functions but no dice.

    Suggestions?

    Posted 10 years ago on Tuesday January 12, 2010 | Permalink
  5. PHP should go in your themes functions.php file, if the code is placed properly in your function.php file, it should work. You may need to double check the code to make sure the syntax is correct and that it appears within a php code block.

    Posted 10 years ago on Tuesday January 12, 2010 | Permalink
  6. Thanks Carl,

    One last question. outside of continuing to troubleshoot email problems on my server, I'm not sure the author email is populating the field. It may be because I'm not specifying the proper parameter via the advanced settings in the form for that field. Using Jan's first code snippet, which parameter should I be using?

    Thanks again for all the help

    Posted 10 years ago on Tuesday January 12, 2010 | Permalink
  7. I guess I'm going to have to seek help to get this going. I don't have the in-house technical expertise to give it a go. Do you have any suggestions on who to contract for this?

    Posted 10 years ago on Wednesday January 13, 2010 | Permalink
  8. Hey Shelley, hit me up via the Contact Us form with details on what you want to do and we can see what the time/effort would be to accomplish what you want to do. Thanks!

    Posted 10 years ago on Thursday January 14, 2010 | Permalink
  9. Jan Egbert
    Member

    This should work if you change the 2 in gform_notification_email_2 to the id of the form you added to your template. You can find the ID in your WordPress backend in the form list. Also if the meta key for the custom field containing the emailaddress is different, you would have to change that. In this example I used the meta key of email_value.

    add_filter( 'gform_notification_email_2', 'route_notification', 10, 2 );
    
    function route_notification($email_to, $entry){
    	global $post;
    	$email_to = get_post_meta($post->ID, "email_value", true);
    	return $email_to;
    
    }
    Posted 10 years ago on Thursday January 14, 2010 | Permalink
  10. Jan, I wanted to let you know that I've partially implemented this, but got pulled away and haven't had a chance to go back and finish. I'll let you know how it goes as soon as I get it done. I just wanted to say thanks, because it LOOKS like it's going to work fine.

    Thanks!

    Posted 10 years ago on Tuesday January 19, 2010 | Permalink
  11. go4
    Member

    This is great. To clarify for anyone wanting to use this: the value of the custom field you pass will override whatever is set in the admin area under the notifications > send to email field for the form.

    Posted 9 years ago on Tuesday April 20, 2010 | Permalink