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.

How to set "reply to" for notifications to: my own address AND senders address

  1. STB
    Member

    Under "Notification to Administrator" you can set the reply-to address to:
    - either one or multiple manually entered adresses
    - OR choose an address from the form with the dropdown box
    How can I set this to both?

    _______________
    Background info:
    We are organizing a campaign where people can express their ideas to politicians, and give the politicians a chance to reply back.

    What I want to achieve is:
    - user fills out a form and expresses his ideas
    - the form sends an email to the politician
    - when the politician replies to the mail, I want the reply go to:
    1) the person who send the mail AND
    2) our own email address

    (NB: I am aware that the politician could remove either one of both addresses when replying, but thats okay. I just want both addresses to be put in the reply-to header by default).

    I have searced the forums, and I think I need to add a filter to my theme's functions.php
    I found this thread: http://forum.gravityhelp.com/topic/in-replace_variables-what-is
    Which is related. But am not sure how to change the codesnippet in that thread to achieve what I want.

    _____________________________________________

    A suggestion for a future release of GF. As it is now, you can EITHER manually choose a 'reply-to' adress OR choose an emailfield from the dropdown.

    Perhaps you put a AND/OR selector in. So that you can choose between:
    1) manually entered OR from drowndown box
    2) manually entered AND from dropdown box

    _____________________________________________

    Finally something I noticed, that you could perhaps find a way to improve in a future revision.

    When editing notifications, the dropdown box for the reply-to address gets reset as soon as you type something in the manual reply-to field.

    * codesnippet fromGF's notification.php:

    <input type="text" name="form_notification_reply_to" id="form_notification_reply_to" onkeydown="jQuery('#form_notification_reply_to_field').val('');" value="<?php echo esc_attr($form["notification"]["replyTo"]) ?>" class="fieldwidth-2" />

    This does check if you typed something with the keyboard in the 'reply to field', but it does not check for putting something in there with your mouse.

    You could copy/paste an emailadress there with the mouse, or if ones browser has stored an emailaddress through the browsers 'auto save formfields' function, you could click the field .. and also choose an emailaddress that way with your mouse.

    Either way, you would end up with both the manual reply-to field having an emailaddress AND the dropdown box having a formfield. It looks like you can have both .. (which is not the case, as after pressing "save settings" .. the manually entered reply-to address gets discarded without warning).

    Perhaps you can change the "onkeydown" to "onchange" or else to " "onfocus" with perhaps some extra code to check if something was filled in, in the manual reply-address.
    Hope this makes sense.

    Posted 13 years ago on Friday November 12, 2010 | Permalink
  2. Thanks for the tip on the small "bug" on the notification script. It makes sense and I will make the change.
    As for your reply to field, you will have to build it from scratch using a hook. Following is a code snippet for it. (Make sure you don't have an email field selected in the admin for the reply to as that will override the reply to field from this hook)

    add_filter("gform_pre_submission_filter", "add_replyto");
    function add_replyto($form){
    
        //Change 84 to your actual form id
        if($form["id"] != 84)
            return;
    
        //Change input_2 and input_3 with your actual input names
        $form["notification"]["replyTo"] = $_POST["input_2"] . "," . $_POST["input_3"];
    
        return $form;
    }
    Posted 13 years ago on Friday November 12, 2010 | Permalink
  3. STB
    Member

    Thanks a lot really for your speedy help Alex!
    But its not working quiet yet.

    I tried using your code in 2 ways.

    *formid=3
    *name of inputfield for users email="input_2"

    1) first way:

    add_filter("gform_pre_submission_filter", "add_replyto");
    function add_replyto($form){
    
        //Change numbers to your actual form id
        if($form["id"] != 3)
            return;
    
        //Change input_2 and input_3 with your actual input names
        $form["notification"]["replyTo"] = $_POST["input_2"] . ",mymail@example.com";
    
        return $form;
    }

    2) second way:
    I added an invisible emailfield to the form (that is, only visible to admins)
    this field had the name "input_6"
    and then used this code:

    add_filter("gform_pre_submission_filter", "add_replyto");
    function add_replyto($form){
    
        //Change numbers to your actual form id
        if($form["id"] != 3)
            return;
    
        //Change input_2 and input_3 with your actual input names
        $form["notification"]["replyTo"] = $_POST["input_2"] . "," . $_POST["input_6"];
    
        return $form;
    }

    But for some reason, both ways .. only the senders email is put into the reply-to header field

    Neither the hardcoded mymail@example.com (1st attempt),
    nor the value of the emailfield with the name "input_6" (2nd attempt)
    are picked up in the reply-to header.

    (I made sure I don't have an email field selected in the admin for the reply to)

    I also tried changing double quotes to single quotes. Shouldnt make a difference here, but tried nonetheless to make sure. But same result.

    Could you please have another look at it? Much appreciated.
    (The first method, hardcoding my own emailaddress in, would be the preferred way for me.)

    Posted 13 years ago on Friday November 12, 2010 | Permalink
  4. Make sure you don't have an email field selected on the notification admin page.
    If that is not the case, send me an WP admin login to alex@rocketgenius.com and a link to your site and I will take a closer look

    Posted 13 years ago on Friday November 12, 2010 | Permalink
  5. STB
    Member

    I take it you meant the "reply-to" email field for admin notification Alex.
    (and not the "send-to" email field)

    The reply-to field is empty indeed.

    I send you an email with the login.
    Thank you in advance once again.

    Posted 13 years ago on Friday November 12, 2010 | Permalink
  6. STB
    Member

    Alex helped me solve this.
    I wish to thank him for his skillful and friendly support.
    Really superb support guys.

    I am putting the final solution up here, so others can benefit from it as well.

    The following code does the trick:

    add_filter("gform_pre_submission_filter", "add_replyto");
    function add_replyto($form){
    
        //Change numbers to your actual form id
        if($form["id"] != 3)
            return $form;
    
        //Change input_2 with your actual input names
        //Change mymail@example.com to your actual emailaddress
        $form["notification"]["replyTo"] = $_POST["input_2"] . ",mymail@example.com";
    
        return $form;
    }

    1) You will need to put this code in your theme's function.php
    (Note: this means the code will keep working if you update the plugin. But just in case you switch theme, you would have to put this code in your new theme's funtion.php)

    2) You need to make sure that you dont have anything in the reply-to fields for admin notification. That means ..
    - no email in the manual reply-to addressbox,
    - but *also* make sure the drop-down box is *not* set to an email field
    (I went wrong here by overlooking this)

    3) You have to change the following In the code to match your situation:

    if($form["id"] != 3)
    set this to the form ID you want this code to work on

    $_POST["input_2"]
    set this to the name of the formfield holding the emailaddress of the person filling out the form

    mymail@example.com
    set this to your own emailaddress that you also want to show up in the reply-to field

    Thanks and cheers!

    Posted 13 years ago on Friday November 12, 2010 | Permalink