skip to Main Content

I am trying to use gform_after_submission to grab a field value(url of a file) then pass the value to a notification so it can be sent as an attachment. This is what I have so far:

add_action("gform_after_submission", "after_submission", 10, 2);
function after_submission($entry, $form){
    $pdf = $entry["3"];
    return $pdf;
}

add_filter( 'gform_notification_3', 'add_notification_attachments', 10, 3 );
function add_notification_attachments( $notification, $form, $entry ) {
    if ( $notification['name'] == 'Admin Notification' ) {
        $path = 'path/to/file.pdf';
        $notification['attachments'] = array( $path );
    }
    return $notification;
}

2

Answers


  1. Chosen as BEST ANSWER

    Thanks Dave, couldn't see your updated code but here's what I managed to do once you told me about converting the URL to a path & it now works perfectly:

        function get_file_path_from_url( $file_url ){
       return realpath($_SERVER['DOCUMENT_ROOT'] . parse_url( $file_url, PHP_URL_PATH ));
    }
    
    add_filter( 'gform_notification_3', 'add_notification_attachments', 10, 3 );
    function add_notification_attachments( $notification, $form, $entry ) {
        if ( $notification['name'] == 'Admin Notification' ) {
            $path = $entry['3'];
            $path = get_file_path_from_url($path);
            $notification['attachments'] = array( $path );
        }
        return $notification;
    }
    

  2. Untested but you shouldn’t need the first action, only the notification filter.

    add_filter( 'gform_notification_3', 'add_notification_attachments', 10, 3 );
    function add_notification_attachments( $notification, $form, $entry ) {
        if ( $notification['name'] == 'Admin Notification' ) {
            $path = $entry['3'];
            $notification['attachments'] = array( $path );
        }
        return $notification;
    }
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search