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.

Different notifications based on conditional logic in form

  1. Hi,

    I posted a reply to another thread about multiple notifications, but felt this situation was slightly different:

    http://www.gravityhelp.com/forums/topic/how-can-i-send-more-than-one-admin-notification

    I was also a bit out of my depth trying to build on the code suggested in that thread. I apologise for originally tagging this on the end of another thread, and I should also say that I am a designer and front-end developer, so there are limitations to my php skills!

    A client of mine has a Gravity Forms powered contact form. In the form is a dropdown select box that allows a user who is filling in the form to choose the type of enquiry. At present, the form uses email routing to send a nicely formatted notification to one of three different email addresses based on this dropdown input. All fine and dandy.

    However, my client now wishes to add a new type of enquiry which I don't know if Gravity Forms can do. The form needs to work exactly as it is doing now for the existing enquiry types. If the new enquiry type is chosen, in only this situation it needs to send an extra different type of notification to a new email address. This notification needs to be plain text, containing JSON with relevant form fields parsed into it.

    I can use email routing to send an email to this new email address, but I have no idea how to send a different type of notification format in only this set of circumstances, or how to define what the content of this notification will be. I have the JSON, provided by my client, but don't know where to put it!

    Any help would be greatly appreciated.

    Thanks

    John

    Posted 7 years ago on Thursday February 7, 2013 | Permalink
  2. David Peralty
    Administrator

    Look half way down the page at the Conditional Shortcode area, and that's how you would create different messages based on user selection:
    http://www.gravityhelp.com/documentation/page/Shortcodes

    Posted 7 years ago on Thursday February 7, 2013 | Permalink
  3. Ooo! Thanks David, this looks like it might be the ticket!

    So just to clarify, I can use those conditional tags in the notification email template to do something like:

    if it is enquiry 1-3, sent this (insert whatever text content I want in the notification email)
    if it is enquiry 4, send this (insert JSON code to be sent)

    Then I can populate the JSON code with submitted form input just like I would with a normal notification email?

    As Columbo would say, one more thing - the notification for the JSON email is going to be sent to PipeDrive, and needs to be plain text, is there any way to handle that?

    Thanks so much,

    John
    :-)

    Posted 7 years ago on Thursday February 7, 2013 | Permalink
  4. David Peralty
    Administrator

    Yes, you'll also need to use the following hook to change the notification type based on the value:
    http://www.gravityhelp.com/documentation/page/Gform_notification_format

    All my best!

    Posted 7 years ago on Thursday February 7, 2013 | Permalink
  5. Hi - I'm really sorry about this, but I don't understand how to implement that hook! Also - where does that code go? functions.php?

    Apologies for not understanding this!

    Posted 7 years ago on Thursday February 7, 2013 | Permalink
  6. David Peralty
    Administrator

    It's all good. Yes, hooks and filters get used in your theme's functions.php file. All my best!

    Posted 7 years ago on Thursday February 7, 2013 | Permalink
  7. Hi - so if I paste the example (edited to apply to a specific form) into my functions.php, then all admin emails (emails sent to staff) will become plain text, but user notifications (emails sent to whoever filled in the form) will stay HTML formatted?

    Posted 7 years ago on Thursday February 7, 2013 | Permalink
  8. Hi,

    I've had a look at Gravity Forms conditional tags, and have spotted a problem which means they might not work for achieving what I want. I'm hoping I am wrong though and that you can put me right!

    To clarify, at present, the form uses email routing to send a nicely formatted notification email to one of three different email addresses based on input from a select box on the form called 'enquiry type'.

    For the new 4th enquiry type, if it is chosen, email routing needs to be able to send a standard notification email (as for the other enquiry types) to one address, but send an additional differently formatted notification email containing the JSON to another email address. As these are both based off the same form input, I can't see how to do this with conditional tags.

    Help!

    Posted 7 years ago on Friday February 8, 2013 | Permalink
  9. David Peralty
    Administrator

    Gravity Forms can't do this by default. You would have to create your own PHP mail script for the second e-mail and shoot it off using one of our submission hooks. Gravity Forms currently doesn't have the ability to send two e-mails from one submission that are different types/content.

    Posted 7 years ago on Friday February 8, 2013 | Permalink
  10. Hi, thanks for the update.

    Your documentation is great so i can probably work out how to use your submission hook to send the extra email, but how would I make sure this only happens if the user has chosen a specific enquiry type?

    Posted 7 years ago on Saturday February 9, 2013 | Permalink
  11. In your function, test for the value being submitted in that form field, and if not, exit the function. If the value was submitted, process your additional email.

    Posted 7 years ago on Saturday February 9, 2013 | Permalink
  12. Thanks for all the help! So am I on the right track with something like his (see code below)

    Hopefully my last question - how would I insert form field content into the extra email? I have some JSON that I need to populate with the form submission at relevant locations, then send as plain text to a CRM system.

    <?php
    
    add_action("gform_notification_format", "set_notification_format", 10, 4);
    function set_notification_format($format, $notification_type, $form, $lead){
    
        if($notification_type == "admin")
            return "text"; //setting admin notifications as text
        else
            return "html"; //setting user notifications as text
    }
    
    add_action('gform_after_submission_1', 'extra_email', 10, 2);
    function extra_email($entry, $form) {
        // change the 5 here to the field ID where your phone number is stored
        $enquirytype = $entry['1'];
    
        // If the type of enquiry is Project Quote, send an extra email
        if ($enquirytype == 'Project Quote') {
    
        $content = "Whatever I want the content of the extra email to be";
    
    	// set your second admin email address here
        wp_mail('admin2@example.net', 'Project Quote email', $content);  
    
        }
    
    }
    ?>
    Posted 7 years ago on Tuesday February 12, 2013 | Permalink
  13. insert form field content into the extra email

    You're retrieving a submitted value on line 15 now. What sort of additional information do you want to add to the email? It will be added in a similar fashion to how the data from $entry['1'] was retrieved, but instead of just using it for a conditional test, just add it to the $content on line 20. Something like this

    [php]
    $content = "Message: " . $entry['5'];

    That would add the value submitted in field 5 of the form to the static text "Message: " and that is what would be sent in your mail function.

    Posted 7 years ago on Wednesday February 13, 2013 | Permalink
  14. Thanks so much for all the help, and bearing with me through all my questions. I'm going to try and implement this tomorrow - fingers crossed I think I have everything I need. :-)

    Posted 7 years ago on Wednesday February 13, 2013 | Permalink
  15. Let us know how it turns out when you're done, or let us know if we can provide more assistance.

    Posted 7 years ago on Sunday February 17, 2013 | Permalink
  16. Hi. Everything worked at the Wordpress / Gravity Forms end, except when I try and send the extra email to PipeDrive, I get an error indicating that PipeDrive isn't reading the email correctly, which may mean the email content isn't as expected. My client is speaking to PipeDrive support to find out what is causing this.

    Posted 7 years ago on Sunday February 17, 2013 | Permalink
  17. Please let us know what you hear. Maybe you just need a minor tweak to the format you are sending.

    Posted 7 years ago on Monday February 18, 2013 | Permalink
  18. Will do - I have documented my work and they're going to get back to me as soon as they know. I think the Gravity Forms side of things worked fine though. :-)

    Posted 7 years ago on Monday February 18, 2013 | Permalink
  19. Sounds good. Thanks for the update.

    Posted 7 years ago on Monday February 18, 2013 | Permalink
  20. Sorry for delay in replying about this - everything worked out fine in the end. Gravity Forms worked a treat. The problem was that Pipedrive didn't like ANY white space (i.e. laying code out nicely) - once I removed all formatting it worked fine. They're even going to implement this method on a second form on the site they liked the results so much.

    Thanks again for all the help. :-)

    Posted 7 years ago on Friday March 15, 2013 | Permalink
  21. Thanks for the update.

    Posted 7 years ago on Sunday March 17, 2013 | Permalink

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