Gravity PDF
[resolved] PDF Not Attaching (8 posts)

  1. AvalonMel
    Posted 3 years ago #

    I've created my own template and tested it using the test url and it displays great. It seemed that no matter what code I changed I couldn't actually get it to trigger when I submitted my form, so I renamed my template to example-template.php Now when I submit my form the PDF is generated and stored on the server and an email is sent to the admin, but the PDF doesn't attach to the email. Help!


  2. Jake Jackson
    Plugin Author

    Posted 3 years ago #


    Have you followed the instructions on setting up the plugin, including notifications, here: http://gravityformspdfextended.com/documentation/2.0.0/1/configuration/

    You'll also need to enable notifications in your form.

    Let me know if you have any problems.

  3. AvalonMel
    Posted 3 years ago #

    Yes, I followed those directions but it's not working. Well...it's saving, but not attaching. I changed if($form_id == 1) to if($form_id == 4) [the id of my form] but nothing. Are there any other variables I need to change?

  4. AvalonMel
    Posted 3 years ago #

    I've compared the Notifications screen of my form to that of the example form and they're identical. I've also compared the form settings. Identical.

    This is the code I've added to my theme's functions.php

    function gform_pdf_create($entry, $form)
        $user_id = $entry['id'];
        $form_id = $entry['form_id'];
        /* only output PDF if the $form_id matches */
    	/* 4 is the ID for the second half of the contract */
        if($form_id == 4)
            /* include the pdf processing file */
           require PDF_PLUGIN_DIR.'render_to_pdf.php';
            /* generate and save default PDF */
            //$filename = PDF_Generator($form_id, $user_id, 'save', true);
            /* comment out the above line and uncomment the line below if you want to use a custom template */
           $filename = PDF_Generator($form_id, $user_id, 'save', true, 'example-template.php', 'EasternEdgePolicyContract.pdf');
    add_action("gform_entry_created", "gform_pdf_create", 10, 2);


    function gform_add_attachment($attachments, $lead, $form){
        $form_id = $lead['form_id'];
        $user_id = $lead['id'];
        $attachments = array();
        $folder_id = $form_id.$user_id.'/';
     	/* 4 is the ID of the second half of the contract */
        if($form_id == 4)
            /* include PDF converter plugin */
            include PDF_PLUGIN_DIR.'render_to_pdf.php';
            //$attachment_file = PDF_SAVE_LOCATION. $folder_id . get_pdf_filename($form_id, $user_id);
            $attachment_file = PDF_SAVE_LOCATION. $folder_id . 'FormName.pdf';
            $attachments[] = $attachment_file;
        return $attachments;
    /* add attachment to both the admin and user notification */
    add_filter("gform_admin_notification_attachments", 'gform_add_attachment', 10, 3);
    add_filter("gform_user_notification_attachments", 'gform_add_attachment', 10, 3);

    Can you help any more?

  5. Jake Jackson
    Plugin Author

    Posted 3 years ago #

    Hi Mel,

    You're using a custom template name but forgot to tell the attachment function to use the new name.

    Change $attachment_file = PDF_SAVE_LOCATION. $folder_id . 'FormName.pdf'; to $attachment_file = PDF_SAVE_LOCATION. $folder_id . 'EasternEdgePolicyContract.pdf'; and you should be fine.

  6. AvalonMel
    Posted 3 years ago #

    Thanks! Figures it was a simple oversight. Now... do you know if there's anyway to access that PDF from a browser after it's been generated? The URL is giving me a 404 even though I can see the file on the server. I need to open up the PDF so that the user can print it (through the website, not through their email program).

  7. Jake Jackson
    Plugin Author

    Posted 3 years ago #

    PDFs on the server are protected via the .htaccess file to stop unwanted people downloading the PDFs. The most secure way to do it is to generate the PDF automatically. There's a description on how to do this in our FAQs: http://gravityformspdfextended.com/faq/i-want-users-to-be-able-to-download-the-pdf-from-the-server/

  8. AvalonMel
    Posted 3 years ago #

    That's close to what I was doing (using $_GET to get the form and entry ID to build the url) but that will make all the difference. Thanks again!

Topic Closed

This topic has been closed to new replies.

About this Plugin

  • Gravity PDF
  • Frequently Asked Questions
  • Support Threads
  • Reviews

About this Topic


No tags yet.