如何将pdf文件附加到重力形式通知中? [英] How do I attach a pdf file to a Gravity Forms Notification?

查看:86
本文介绍了如何将pdf文件附加到重力形式通知中?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

重力表单提供了一种从文件上传器附加文件的方法(请参见下面的代码),但是我将如何更改此代码以仅从隐藏字段值附加我自己的PDF文件或将pdf文件粘贴到此代码中?我尝试了一些尝试,但是没有成功.任何帮助将不胜感激!

Gravity forms offers a way to attach files from the file uploader (See code below), but how would I change this code to simply attach my own PDF file from either a hidden field value or simply paste the pdf file within this code? I tried a few things but it didn't work. Any help would be appreciated!

 add_filter( 'gform_notification', '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['name'] == 'User Notification' ) {

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

    if(!is_array($fileupload_fields))
        return $notification;

    $attachments = 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 ) {
            $attachments[] = $attachment;
        }
    }

    $notification['attachments'] = $attachments;

}

return $notification;
  }

推荐答案

基于该代码,类似的事情应该起作用.将$ url值替换为PDF的URL.

Based on that code, something like this should work. Replace the $url value with the URL to your PDF.

add_filter( 'gform_notification', 'change_user_notification_attachments', 10, 3 );
function change_user_notification_attachments( $notification, $form, $entry ) {

    if ( $notification['name'] == 'User Notification' ) {
        $url = 'http://yoursite.com/path/to/file.pdf';
        $notification['attachments'] = array( $url );
    }

    return $notification;
}

这篇关于如何将pdf文件附加到重力形式通知中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆