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.

replace_variables() question

  1. In the common.php, in the method replace_variables() what is $lead supposed to be? I'm trying to create a hook that will allow me to create a "tell a friend" to email more than one person at a time and it's almost there, I just need to be able to get the user notification message to parse the variables such as {all_fields} and what not. Or is there another way to go about it?

    Posted 14 years ago on Monday February 22, 2010 | Permalink
  2. If all you want to do is send the notification to more than one person, I think there is an easier way to do this with existing hooks.
    Can you explain what exactly you are trying to accomplish? I can come up with a code snippet to get the job done.

    Posted 14 years ago on Monday February 22, 2010 | Permalink
  3. Sure, what we are looking to do is create a "Tell A Friend" form which allows you to email a page to x amount of people at a time. So your basic form may look like:

    Your Name
    Your Email
    Friend 1 Email
    Friend 2 Email
    Friend 3 Email
    Friend 4 Email
    Friend 5 Email

    When you submit the form it'll kick out an "invitation" email to Friends 1 - 5. The problem currently is that in the Notifications, the Bcc field doesn't allow for the gravity form custom tags {foo}.

    Currently I have my function hooked into gform_post_submission, and it loops through the results. I'm able to isolate the friend email addresses, however, I still want to use certain aspects of GForms so the client can maintain the form easily. Such as the Message field in the Notification to User area. And I can isolate that output as well but I'm not able to convert the GForms tags.

    Posted 14 years ago on Tuesday February 23, 2010 | Permalink
  4. What you need to do is use the pre_submission hook and programatically add the emails to the form's BCC field. I will send you a code snippet to get you started soon.

    Posted 14 years ago on Wednesday February 24, 2010 | Permalink
  5. Try the following code snippet. NOTE: You will need to change the input ids and the form id to match your values.

    add_filter("gform_pre_submission_filter", "add_bcc");
    function add_bcc($form){
        //change 2 to your actual form id
        if($form["id"] != 2)
            return;
    
        //Change the following input ids to match your fields.
        $bcc  = $_POST["input_9"] . ","; //friend 1 email
        $bcc .= $_POST["input_11"] . ","; //friend 2 email
        $bcc .= $_POST["input_13"] . ","; //friend 3 email
        $bcc .= $_POST["input_15"] . ","; //friend 4 email
        $bcc .= $_POST["input_17"]; //friend 5 email
    
        $form["notification"]["bcc"] = $bcc;
        return $form;
    }
    Posted 14 years ago on Wednesday February 24, 2010 | Permalink
  6. Hello,

    This is just what I've been looking for - I've been trying to get this to work and I cant seem to! Any chance of some help? :)

    I've pasted the above code into my functions.php file (at the bottom - if that makes any difference), I've changed the form id, and I've changed those input id's too. However, when I submit the form it just sends the message to the first person in the list.

    My notifications are set to go to users and the to email field is set to be sent to the person that's submitting the form.

    What else could I be doing wrong?

    Thanks,
    Steph

    Posted 14 years ago on Sunday March 7, 2010 | Permalink
  7. Steph, you would have to post the code you are trying to use here so we can take a look at it. When putting code in your forum post, be sure to surround the code block between backtick ( ` ) characters so it will format it as code.

    Posted 14 years ago on Monday March 8, 2010 | Permalink
  8. Hi Carl,

    I'm using this code....

    add_filter("gform_pre_submission_filter", "add_bcc");
    function add_bcc($form){
        //change 2 to your actual form id
        if($form["id"] != 10)
    return;
        //Change the following input ids to match your fields.
        $bcc  = $_POST["input_5"] . ","; //friend 1 email
        $bcc .= $_POST["input_6"] . ","; //friend 2 email
        $bcc .= $_POST["input_7"] . ","; //friend 3 email
        $bcc .= $_POST["input_8"] . ","; //friend 4 email
        $bcc .= $_POST["input_9"]; //friend 5 email
    
        $form["notification"]["bcc"] = $bcc;
        return $form;
    }

    Steph

    Posted 14 years ago on Monday March 8, 2010 | Permalink

This topic has been resolved and has been closed to new replies.