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.

conditional logic for user notifications

  1. hey ,
    I was wondering if I can use some sort of code or condition to sent out certain email content (pdf link) based on the chosen checkbox... so for instance
    1- belt guard
    2- safety guard
    3 - catalogue

    the user checks a box and then recieves the pdf associated with that box
    Thanks in advance

    Posted 13 years ago on Tuesday August 9, 2011 | Permalink
  2. Gravity Forms does not email attachments. A good explanation of why:

    http://www.gravityhelp.com/forums/topic/emails-with-attachments#post-30297

    Normally you would put a link to the PDF in the user notification email. Sounds like you want different PDFs though based on a choice made in the form. You can use something like this to change the body of the notification based on a user's choice in the form:

    http://www.gravityhelp.com/forums/topic/dynamically-send-email-with-different-contents#post-16503

    That code will go in your functions.php and will need to be modified to handle all your conditions, change the form ID and field etc, etc.

    Instructions on where to put that code:
    http://www.gravityhelp.com/documentation/page/Where_Do_I_Put_This_Code%3F

    Posted 13 years ago on Tuesday August 9, 2011 | Permalink
  3. Thanks alot Ill give it a shot!

    Posted 13 years ago on Tuesday August 9, 2011 | Permalink
  4. Please let us know if you need help.

    Posted 13 years ago on Tuesday August 9, 2011 | Permalink
  5. Ok so do I create my conditional function in the theme-functions.php, and then where do I use the function itself? Little confused , im a bit new to wordpress so. I know how to code just the structure is different Im used to MVC

    Posted 13 years ago on Tuesday August 9, 2011 | Permalink
  6. no reply? anyone? lol

    Posted 13 years ago on Friday August 12, 2011 | Permalink
  7. Sorry about the delay. Here's what I did in functions.php (you may need to use theme-functions.php based on how your theme does it):

    http://pastebin.com/CwsM2FjF

    You will need to change the 19 on line 2 to your form ID.

    You will need to change 3 on line 6 to your field ID. I used a multiple choice field (radio buttons) to accept just one request for PDF.

    [There is nothing to add anywhere else. This function is a filter which just modifies values submitted with this form. There is no function to be added anywhere else.]

    When I set up my multiple choice field, I chose to use values to avoid issues with the values having capital letters and spaces. So, my values are beltguard, safetyguard and catalogue. You could use numbers there, or the actual names of your PDF to use later as variable replacements.

    So, based on the value of input_3, I append to the email notification the link to the PDF I want to send. I set up the user email notification the same as always, but just left a blank line and the end and then this function adds a link to the end of the email body. I disabled auto-formatting for the notification and added my HTML manually (which is why there is a closing < /p> after the link in functions.php) Then, return the modified form object with the PDF link inserted into it.

    Hopefully that will get you pointed in the right direction. If you need more help please let us know. Thanks.

    Posted 13 years ago on Friday August 12, 2011 | Permalink
  8. I found an easier way while looking through some older posts tonight:

    http://www.gravityhelp.com/forums/topic/automate-a-file-send-with-form-submit#post-29223

    Maybe that will work in your case.

    Posted 13 years ago on Monday August 15, 2011 | Permalink
  9. thank you for your response and help, Im going to give it a shot tomorrow :)

    Posted 13 years ago on Thursday August 18, 2011 | Permalink
  10. just reading through your replies , it looks almost too easy! :) thanks again for your time and help its greatly appreciated

    Posted 13 years ago on Thursday August 18, 2011 | Permalink
  11. I'm confident you will get it to work. Please post if you need additional help.

    Posted 13 years ago on Thursday August 18, 2011 | Permalink
  12. hmmm looked easier than I thought , I had to use checkboxes instead or a dropdown to allow for multiple values, so because of this , it ruled out your last suggestion. Heres what I added :

    add_filter('gform_pre_submission_filter_2', 'conditional_message');
    function conditional_message($form){
    
            // update the "3" following "input_" to the ID of your field
            $choice1 = RGForms::post('input_7_1');
            $choice2 = RGForms::post('input_7_2');
            $choice3 = RGForms::post('input_7_3');
            // append a different PDF link based on the interest
            // I used values to avoid capitalization and spaces in my values
    
            if($choice1 || $choice2 || $choice3)
                    $form['autoResponder']['message'] .= "Thank You";
    
                if($choice1)
                    $form['autoResponder']['message'] .= "<a href='http://kreatorsafety.com/uploads/belt_guard.pdf' title='Download your free Belt Guard Data Sheet' rel="nofollow">BELT GUARD DATA SHEET DOWNLOAD</a></p>";
                if($choice2)
                    $form['autoResponder']['message'] .= "<a href='http://kreatorsafety.com/uploads/coupling.pdf' title='Download your free Safety Guard Data Sheet' rel="nofollow">COUPLING GUARD DATA SHEET DOWNLOAD</a></p>";
                if($choice3)
                    $form['autoResponder']['message'] .= "<a href='http://kreatorsafety.com/uploads/K.S.Catalogue.pdf' title='Download your free Catalogue here' rel="nofollow">SAFETY GUARD CATALOGUE DOWNLOAD</a></p>";
    
            // return modified form
            return $form;
    }

    ID of the form is "2" and the input names are listed accordingly . still not working though :(

    Posted 13 years ago on Tuesday August 23, 2011 | Permalink
  13. I did this in the "theme-functions.php" located in the child-theme that I created.

    Posted 13 years ago on Tuesday August 23, 2011 | Permalink
  14. just realized I put the actual links there lol , anyways you can check out the site if you want to see what Im trying to do
    Thanks in advance

    Posted 13 years ago on Tuesday August 23, 2011 | Permalink
  15. Does your theme use a theme-functions.php for custom functions, or should it be using functions.php? Normally themes just use functions.php. Your theme could be including that file, but I just want to make sure it is. Was there already a theme-functions.php file, and you just added to it? Or do you have a functions.php file present?

    Posted 13 years ago on Wednesday August 24, 2011 | Permalink
  16. no theme-functions.php file was there already

    Posted 13 years ago on Thursday August 25, 2011 | Permalink
  17. What is the URL for the page with this form on it?

    Is it form 2? And is it field 7?

    Posted 13 years ago on Thursday August 25, 2011 | Permalink
  18. http://kreatorsafety.com/download-catalogue/

    Posted 13 years ago on Saturday August 27, 2011 | Permalink
  19. I think the inputs should be named like this:

    [php]
    $choice1 = RGForms::post('input_7.1');
    $choice2 = RGForms::post('input_7.2');
    $choice3 = RGForms::post('input_7.3');

    A dot rather than an underscore after the input_7. That's based on the input names from your form. You switched to checkboxes there from radio (due to the need to allow multiple selections) and I didn't catch that.

    Posted 13 years ago on Sunday August 28, 2011 | Permalink
  20. hmm I did fix the "." for the inputs, still not working though :S..... so just to recap what I have done
    1. Add the following to the "theme-functions.php" located in the "/includes" which is in the child directory.

    [php]
    add_filter('gform_pre_submission_filter_2', 'conditional_message');
    function conditional_message($form){
    
            // update the "3" following "input_" to the ID of your field
            $choice1 = RGForms::post('input_7.1');
            $choice2 = RGForms::post('input_7.2');
            $choice3 = RGForms::post('input_7.3');
            // append a different PDF link based on the interest
            // I used values to avoid capitalization and spaces in my values
    
            if($choice1 || $choice2 || $choice3)
                    $form['autoResponder']['message'] .= "Thank You";
    
                if($choice1)
                    $form['autoResponder']['message'] .= "<a href='http://kreatorsafety.com/uploads/belt_guard.pdf' title='Download your free Belt Guard Data Sheet' rel="nofollow">BELT GUARD DATA SHEET DOWNLOAD</a></p>";
                if($choice2)
                    $form['autoResponder']['message'] .= "<a href='http://kreatorsafety.com/uploads/coupling.pdf' title='Download your free Safety Guard Data Sheet' rel="nofollow">COUPLING GUARD DATA SHEET DOWNLOAD</a></p>";
                if($choice3)
                    $form['autoResponder']['message'] .= "<a href='http://kreatorsafety.com/uploads/K.S.Catalogue.pdf' title='Download your free Catalogue here' rel="nofollow">SAFETY GUARD CATALOGUE DOWNLOAD</a></p>";
    
            // return modified form
            return $form;
    }

    I also if you noticed changed your case to a simple if statment.
    2. I have the "Notification to User" enabled in the back end under the form editor

    Im not sure what else to do

    Posted 13 years ago on Monday August 29, 2011 | Permalink
  21. as far as the back end goes... what should I have enabled or disabled?. Should I keep the html editor blank also? Does this matter?

    Posted 13 years ago on Monday August 29, 2011 | Permalink
  22. Hi Dave. Can you export the form and attach it to an email sent to chris@rocketgenius.com ? It doesn't make sense. If you have the opportunity, attach your functions.php. I will install it locally and see if I can find the problem. Thanks.

    Posted 13 years ago on Tuesday August 30, 2011 | Permalink
  23. Thank you very much Chris I really do appreciate your help . sorry for any inconvenience

    Posted 13 years ago on Friday September 2, 2011 | Permalink
  24. Wow, not sure how I got the information wrong in the comment above. The inputs are correct as:

    • input_7_1
    • input_7_2
    • input_7_3
    Posted 13 years ago on Friday September 2, 2011 | Permalink
  25. did you get it working?

    Posted 13 years ago on Tuesday September 6, 2011 | Permalink
  26. I did. Here's the code:
    http://pastebin.com/Sb8PSPyX

    Here's a test page with your form (I changed the notification emails to come from me):
    http://gravity.chrishajer.com/request-a-brochure/

    If you use your email address when submitting, you will get the conditional autoresponder email with links to the PDFs based on your check box selections.

    I did email you as well (Fri, Sep 2, 2011 at 4:30 PM), in response to the XML form you sent me. I forwarded that original email to you again just now. Please check for the new copy.

    Posted 13 years ago on Thursday September 8, 2011 | Permalink
  27. wow thanks for the help I got it !!!, one note for people in the future.... make sure you are editing the right theme-functions.php if you have a child-theme . I was editing the wrong theme-functions.php

    Posted 13 years ago on Friday September 9, 2011 | Permalink
  28. Thanks for the update Dave. Glad you got it worked out.

    Posted 13 years ago on Friday September 9, 2011 | Permalink
  29. Worked great! Thanks for taking the time to share this code. It saved me a lot of time. A lot.

    Posted 12 years ago on Monday February 13, 2012 | Permalink
  30. To add to what was referenced here, if you want to physically attach a file to an email notification that is possible with Gravity Forms v1.6.3 which is currently a beta test release here on the support site downloads page.

    There are new hooks available that let's you use custom PHP to attach files to the email notifications. You can find documentation for these new hooks and how to use them below.

    gform_user_notification_attachments
    http://www.gravityhelp.com/documentation/page/Gform_user_notification_attachments

    gform_admin_notification_attachments
    http://www.gravityhelp.com/documentation/page/Gform_admin_notification_attachments

    Both include examples of how to automatically include all file uploads associated with that form as attachments to the email notification. But you can customize it to suit your needs if you simply want to attach a specific file.

    Posted 12 years ago on Monday February 13, 2012 | Permalink

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