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.

From an "upload field" --> can it be sent to me as an email attachment?

  1. Hello.

    I am about to purchase my Gravity Forms license. One thing I would like to know first, though, is if I'll be able to do the following: a user will submit a form consisting of some information such as name/address/etc. as well as an uploaded image. Will I be able able to submit the information (name/address/etc.) as an email and have the uploaded image be attached to the email?

    Edit: I also have a second question, a bit more complicated: is it possible to make a condition for upload fields, such as this: user enters the "number of images" and that many upload fields are given? (these are the images I would like to be emailed as attachments, by the way)

    Much appreciated!

    - Dan

    Posted 12 years ago on Thursday June 7, 2012 | Permalink
  2. Q1. You can attach uploaded images to your notification. Please see the gform_user_notification_attachments filter for this customization.

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

    Q2. You can accomplish this functionality with minor differences. If you allow from 1 to 9 images (or any finite number of images) you can include conditional logic to show that number of fields for upload. You can then include all the images as attachments. It will require a bit of PHP code but it can be done.

    Let us know if you have any more questions. Thank you.

    Posted 12 years ago on Monday June 11, 2012 | Permalink
  3. AlwaysMe3
    Member

    Do we just place the supplied code in the specified location and it will work? or do we need to change it relative to our website or forms?

    Posted 12 years ago on Friday July 20, 2012 | Permalink
  4. David Peralty

    You will almost always need to change the code related to the field and form ids that you have. It should also always go in the functions.php file unless it is JS or CSS. Have a look at this:
    http://www.gravityhelp.com/documentation/page/Where_Do_I_Put_This_Code%3F

    Posted 12 years ago on Friday July 20, 2012 | Permalink
  5. AlwaysMe3
    Member

    So I added this code, but I need to know where to specify form or field id in order for it to work, because uploads are still not being sent as attachments. Thanks.

    add_filter("gform_user_notification_attachments", "add_attachment", 10, 3);
    
    function add_attachment($attachments, $lead, $form){
    
        $fileupload_fields = GFCommon::get_fields_by_type($form, array("fileupload"));
    
        if(!is_array($fileupload_fields))
            return $attachments;
    
        $attachments = array();
        $upload_root = RGFormsModel::get_upload_root();
        foreach($fileupload_fields as $field){
            $url = $lead[$field["id"]];
            $attachments[] = preg_replace('|^(.*?)/gravity_forms/|', $upload_root, $url);
        }
    
        return $attachments;
    }
    ?>
    Posted 12 years ago on Sunday July 29, 2012 | Permalink
  6. AlwaysMe3
    Member

    Update: it is code for user notification attachments. Can I modify to admin notification? Is there a filter for that?

    Posted 12 years ago on Sunday July 29, 2012 | Permalink
  7. Sounds like you have purchased Gravity Forms? If so, I would like to move this to the regular support forums. Can you access topics in this forum:

    http://www.gravityhelp.com/forums/forum/gravity-forms

    If so, I will move this topic and continue there. We try not to handle actual support in the Pre-purchase forum. Thank you.

    Posted 12 years ago on Sunday July 29, 2012 | Permalink