# Attach select file uploads to notification but not all

**URL:** <https://community.gravityforms.com/t/attach-select-file-uploads-to-notification-but-not-all/2487>\
**Category:** Get Help\
**Tags:** custom, notifications, gform\_notification, attachments\
**Created:** [August 16, 2019, 9:37pm UTC](https://community.gravityforms.com/t/attach-select-file-uploads-to-notification-but-not-all/2487 "2019-08-16T21:37:30Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![user5b9a6031249674.5](https://sea2.discourse-cdn.com/flex020/user_avatar/community.gravityforms.com/user5b9a6031249674.5/32/948_2.png) [@user5b9a6031249674.5](https://community.gravityforms.com/u/user5b9a6031249674.5)\
**Post date:** [August 16, 2019, 9:37pm UTC](https://community.gravityforms.com/t/attach-select-file-uploads-to-notification-but-not-all/2487/1 "2019-08-16T21:37:30Z")

</div>

In our business we need to appoint our new hires with our partner companies. That usually means sending separate emails to 30+ companies with separate attachments (company specific forms) and other common information. I’m trying to build a form that allows me to enter info like name, DOB, email, etc plus 30+ separate upload fields where I can upload the company-specific forms for company A, company B, company C, etc. I then want notifications to go out to each of those 30+ companies with the common information but just their company-specific form attached to their notification. The attachment can’t be hyperlinked in the body of the email. Most of these companies have IT security rules that prevent them from accessing the hyperlinked files.

I can’t find a way to do this. Does anyone know if this can be done?

---

<div class="post-metadata">

**Author:** ![chrishajer](https://sea2.discourse-cdn.com/flex020/user_avatar/community.gravityforms.com/chrishajer/32/88_2.png) [@chrishajer](https://community.gravityforms.com/u/chrishajer)\
**Post date:** [August 17, 2019, 7:07pm UTC](https://community.gravityforms.com/t/attach-select-file-uploads-to-notification-but-not-all/2487/2 "2019-08-17T19:07:20Z")

</div>

It can be done. It would require some customization using the gform\_notification filter to actually conditionally attach the correct upload to the proper notification.

> **[gform\_notification - Gravity Forms Documentation](https://docs.gravityforms.com/gform_notification/)**
>
> Modify a notification object before it is converted into an email and sent.

---

<div class="post-metadata">

**Author:** ![user5b9a6031249674.5](https://sea2.discourse-cdn.com/flex020/user_avatar/community.gravityforms.com/user5b9a6031249674.5/32/948_2.png) [@user5b9a6031249674.5](https://community.gravityforms.com/u/user5b9a6031249674.5)\
**Post date:** [August 19, 2019, 6:59pm UTC](https://community.gravityforms.com/t/attach-select-file-uploads-to-notification-but-not-all/2487/3 "2019-08-19T18:59:50Z")

</div>

Thanks, I’ll take a look at that.

---

<div class="post-metadata">

**Author:** ![user5b9a6031249674.5](https://sea2.discourse-cdn.com/flex020/user_avatar/community.gravityforms.com/user5b9a6031249674.5/32/948_2.png) [@user5b9a6031249674.5](https://community.gravityforms.com/u/user5b9a6031249674.5)\
**Post date:** [August 19, 2019, 7:19pm UTC](https://community.gravityforms.com/t/attach-select-file-uploads-to-notification-but-not-all/2487/4 "2019-08-19T19:19:50Z")

</div>

I found the code you are referencing, but I can’t figure out the variables that I need to use. I have this code pasted into my functions.php file of my child theme.

`add_filter(` `'gform_notification_32'` `,` `'change_user_notification_attachments'` `, 10, 3 );`

`function` `change_user_notification_attachments(` `$notification` `,` `$form` `,` `$entry` `) {`

`` `//There is no concept of user notifications anymore, so we will need to target notifications based on other criteria, such as name`

`` `if` `(` `$notification` `[` `'test notification'` `] ==` `'User Notification'` `) {`

`` `$fileupload_fields` `= GFCommon::get_fields_by_type(` `$form` `,` `array` `(` `'fileupload'` `) );`

`` `if` `( !` `is_array` `(` `$fileupload_fields` `) )`

`` `return` `$notification` `;`

`` `$notification` `[` `'attachments'` `] = (` `is_array` `( rgget(` `'attachments'` `,` `$notification` `) ) ) ? rgget(` `'attachments'` `,` `$notification` `) :` `array` `();`

`` `$upload_root` `= RGFormsModel::get_upload_root();`

`` `foreach` `(` `$fileupload_fields` `as` `$field` `) {`

`` `$url` `=` `$entry` `[` `$field` `->id];`

`` `$attachment` `= preg_replace(` `'|^(.*?)/gravity_forms/|'` `,` `$upload_root` `,` `$url` `);`

`` `if` `(` `$attachment` `) {`

`` `$notification` `[` `'attachments'` `][] =` `$attachment` `;`

`` `}`

`` `}`

`` `}`

`` `return` `$notification` `;`

`}`

I’m working with a test form (form ID=32) and have a single notification called “test notification” and I have two file upload fields, {File:1} and {File:2}. How would I change to above code to only attach {File:1}?

---

<div class="post-metadata">

**Author:** ![user5b9a6031249674.5](https://sea2.discourse-cdn.com/flex020/user_avatar/community.gravityforms.com/user5b9a6031249674.5/32/948_2.png) [@user5b9a6031249674.5](https://community.gravityforms.com/u/user5b9a6031249674.5)\
**Post date:** [August 23, 2019, 3:17pm UTC](https://community.gravityforms.com/t/attach-select-file-uploads-to-notification-but-not-all/2487/5 "2019-08-23T15:17:58Z")

</div>

Bump.

I’d really appreciate help with this. It’s the last piece I need to figure out on a large scale form I’m building.

---

<div class="post-metadata">

**Author:** ![richardw8k](https://sea2.discourse-cdn.com/flex020/user_avatar/community.gravityforms.com/richardw8k/32/2354_2.png) [@richardw8k](https://community.gravityforms.com/u/richardw8k)\
**Post date:** [January 4, 2022, 5:20pm UTC](https://community.gravityforms.com/t/attach-select-file-uploads-to-notification-but-not-all/2487/6 "2022-01-04T17:20:52Z")

</div>


