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.

Having form content sent to me and to email from WP custom field

  1. mcdarwin
    Member

    I have a site with company-profiles - one post has one company listed.

    I wan't to put a Gravity Form on each post and when users submit it I get the content by email and the company gets the content by email. I have the different company emails stored in WP custom fields for their post.

    I remember having read something about this in the forum before, but now I can't find it again.

    Please let me know how I can accomplish this - that will be very helpful...

    Thanks!

    Posted 14 years ago on Wednesday May 5, 2010 | Permalink
  2. Try the following, replacing 5 (in gform_notification_email_5) with your form id, and "email_custom_field_key" with your actual custom field key.

    add_filter("gform_notification_email_5", "route_notification", 10, 2);
    function route_notification($email_to, $entry){
        global $post;
        $company_email = get_post_meta($post->ID, "email_custom_field_key", true);
        return $email_to . ',' . $company_email;
    }
    Posted 14 years ago on Wednesday May 5, 2010 | Permalink
  3. mcdarwin
    Member

    Thanks!

    In which file should I add this?

    Posted 14 years ago on Monday May 10, 2010 | Permalink
  4. It would go in your themes functions.php file.

    Posted 14 years ago on Monday May 10, 2010 | Permalink
  5. mcdarwin
    Member

    It works! Brilliant and very simple solution - Thanks!

    Posted 14 years ago on Tuesday May 11, 2010 | Permalink
  6. cnymike
    Member

    I have attempted to utilize a WP custom field to hold the form recipient email address and when I add the suggested code above to the functions.php file I have an immediate problem.

    As soon as I "update file", the code appears in the functions.php file in the editor but also appears in the dashboard at the top of the window.When I refresh my page, the code remains on the screen while the rest of the screen is white. NOt sure what is causing this but if I backpage to the editor and remove the code and update file again, then everything reverts to normal. So In other words, it's not working for me.

    I had altered the code to reflect my specific situation...

    //GravityForms to use custom field for email delivery address
    add_filter("gform_notification_email_1", "route_notification", 10, 2);
    function route_notification($email_to, $entry){
        global $post;
        $company_email = get_post_meta($post->ID, "email", true);
        return $email_to . ',' . $company_email;
    }

    Whereby my form ID was "1" and the custom field name was "email".

    I can't provide a link to the form since this site is live and I can't really "break" my site just so that I can provide a link to the form.

    Wondering what is wrong?

    Posted 14 years ago on Tuesday June 1, 2010 | Permalink
  7. cnymike
    Member

    I just discovered that the code snippet was placed outside of the closing php tag. That was causing the weird display of code at the top of the dashboard. Moving it inside the closing tag solved that.

    Posted 14 years ago on Tuesday June 1, 2010 | Permalink
  8. cnymike
    Member

    The form is not being received to the WP Custom Field email address. If have admin and user notifications turned on, I get those. But something is preventing the form submission from being received by the custom field address.

    My WP custom field name is "email", my form ID is "1" and my functions.php code snippet is

    //GravityForms to use custom field for email delivery address
    add_filter("gform_notification_email_1", "route_notification", 10, 2);
    function route_notification($email_to, $entry){
        global $post;
        $company_email = get_post_meta($post->ID, "email", true);
        return $email_to . ',' . $company_email;
    }

    Any Ideas why this isn't working?

    Posted 14 years ago on Tuesday June 1, 2010 | Permalink
  9. cnymike
    Member

    I have not had any success getting this to work. Notification to administrator and notification to user works when the form is submitted, so I know that the my server is able to send out email. However the form is not being sent to the WP Custom Field, "email". I imagine this is a simple oversight in the snippet that I've overlooked but so far I'm not able to discern what it is.

    A code snippet was in the forum and that is what I'm currently using although I modified it to use my Form ID and custom field name...

    //GravityForms to use custom field for email delivery address
    add_filter("gform_notification_email_1", "route_notification", 10, 2);
    function route_notification($email_to, $entry){
        global $post;
        $company_email = get_post_meta($post->ID, "email", true);
        return $email_to . ',' . $company_email;
    }
    Posted 14 years ago on Wednesday June 2, 2010 | Permalink
  10. If you can send me your FTP info to alex[at]rocketgenius.com, I will be glad to take a look at this for you and see what is causing the problem.

    Posted 14 years ago on Wednesday June 2, 2010 | Permalink
  11. cnymike
    Member

    I've just emailed you the info. Thank you for taking a look at this.

    Posted 14 years ago on Wednesday June 2, 2010 | Permalink