Skip to content

Instantly share code, notes, and snippets.

@irkanu
Created October 3, 2014 18:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save irkanu/9360e05790bd2cd7d396 to your computer and use it in GitHub Desktop.
Save irkanu/9360e05790bd2cd7d396 to your computer and use it in GitHub Desktop.
Gravity Form upload as attachment
// gform_notification_FORMID, custom_function
add_filter('gform_notification_1', 'gfuaa_upload_attachment', 10, 3);
// http://gravityformspdfextended.com/topic/file-upload-as-attachments/
function gfuaa_upload_attachment( $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["name"] == "Admin Notification"){
$fileupload_fields = GFCommon::get_fields_by_type($form, array("fileupload"));
if(!is_array($fileupload_fields))
return $notification;
$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;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment