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.

Dynamically Email Current Author

  1. Hi, I am trying to use the route notification hook to dynamically send the form to the Current Authors Page. To be clear I do not mean the current Posts Author, but if I were to go to the authors profile page: http://mysite.com/author/dangavin I would see an email form that I can fill out and send to this author.

    I have found the hook and have tried multiple variations, but with no luck. any ideas?

    I am passing this on the author template already:

    $curauth = (isset($_GET['author_name'])) ? get_user_by('slug', $author_name) : get_userdata(intval($author));

    So I was hoping something like this would work... but no luck

    add_filter( 'gform_notification_email_1', 'route_notification' );
    function route_notification($email_to) {
        global $post;
        $email_to = $curauth->user_email;
        return $email_to;
    }
    Posted 13 years ago on Tuesday May 31, 2011 | Permalink
  2. Okay turns out I figured it out about 15 mins after I posted here... This might not be the best solution, but it is working!

    I am assuming you have this on your author page:

    $curauth = (isset($_GET['author_name'])) ? get_user_by('slug', $author_name) : get_userdata(intval($author));

    First, you need to create a hidden field in your form:

    - Edit your Form
    - Add a hidden field you want to populate and give it a name
    - Edit the hidden field
    - Select the Advanced tab
    - Select the "Allow field to be populated dynamically" checkbox
    - Give the field a parameter name, this parameter name is used to target the field so name it something simple like "email" or something similar.
    - Save your form

    Then you would use the gform_field_value hook by adding custom code in your themes functions.php file to dynamically populate that field. For example, if you set the parameter to "email" your code would look like this:

    in your functions.php file add this:

    // NO ID after value_email
    add_filter( 'gform_field_value_email', 'populate_email' );
    function populate_email(){
     global $curauth;
    	return $curauth->user_email;
    }

    and then again in your functions.php file add this:

    // update the '1' to the ID of your form
    add_filter("gform_notification_email_1", "change_notification_email", 10, 2);
    function change_notification_email($email, $form){
    
        // update the '5' to the ID of your field
        $email = $_POST['input_5'];
    
        return $email;
    }

    Remember to change your ID's to reflect your form.

    Posted 13 years ago on Wednesday June 1, 2011 | Permalink
  3. Looks good, Dan!

    The only issue I saw (and this was actually due to a small error in the documentation) is that it is not the $form object that is passed to this hook but the $lead.

    This means you don't have to worry about getting the variable form the $_POST, you can get it straight from the $lead like so:

    [php]
    $email = $lead['5'];

    Nice work! :)

    Posted 13 years ago on Wednesday June 1, 2011 | Permalink
  4. Awesome. Thanks David!

    Posted 13 years ago on Thursday June 2, 2011 | Permalink