• Resolved violetant

    (@violetant)


    I want the generated pdf to be opened in a new tab (new page).
    I saw the following previous answer:

    The above will allow you to create a download link in normal circumstances but it will not work due to your redirect configuration.

    Unfortunately, there is no easy feature in the plugin right now to allow you to post a download link on the thank you page, however, you might be able to set it up manually.

    What you can do is use the “save” feature to save the generated PDF on in your “wp-content/uploads” folder somewhere. Then, you can post a link to it on your thank you page. You will need to use CF7 mail-tags (in save path) and WP shortcodes (in download link) to make sure the link is unique per visitor.

    Another idea is to pass your download link to your thank you page in javascript when you are doing your redirect action.

    I do understand how have to save the pdf with the email shortcodes in the plugin menu. But I dont know how to set up the wordpress page so it gets the right file. There is mentioned shortcodes? Can you give me an example of how to build the url?

    Another way would be javascript. How would I save the url in javascript and insert it in new page where I embed the pdf?

    Is it right that all users will be able to access the pdfs?

    • This topic was modified 2 years, 10 months ago by violetant.
    • This topic was modified 2 years, 10 months ago by violetant.
Viewing 1 replies (of 1 total)
  • Plugin Author maximum.software

    (@maximumsoftware)

    Here is one possible solution:

    We will write a tiny plugin that will create a CF7 special mail-tag and a WP shortcode. Both will output a “user session id” that will be stored in user’s cookies. The filled PDF will be saved on the web server at a path that contains the session id and the redirect page will link to that same location (via the shortcode).

    <?php
    /*
    Plugin Name: CF7 special session id mail-tag and WP shortcode
    Version:     0.1
    */
    
    add_filter('wpcf7_special_mail_tags', 'wpcf7_session_id', 10, 3);
    function wpcf7_session_id($output, $name, $html)
    {
            if($name == '_session_id')
            {
                    if(!isset($_COOKIE['wpcf7_session_id']))
                    {
                            $id = uniqid();
                            setcookie('wpcf7_session_id', $id, time() + 24*60*60, "/");
                            $_COOKIE['wpcf7_session_id'] = $id;
                    }
                    $output = $_COOKIE['wpcf7_session_id'];
            }
            return $output;
    }
    
    add_shortcode('wpcf7_session_id', 'wpcf7_session_id_get');
    function wpcf7_session_id_get()
    {
            return isset($_COOKIE['wpcf7_session_id'])?$_COOKIE['wpcf7_session_id']:"";
    }

    To configure the CF7 form PDF attachment options, we will use the following:
    Filename: document
    Save PDF file on server: pdfs/[_session_id]/

    To configure the redirect page, we will link our download button to the following URL:
    /wp-content/uploads/pdfs/[wpcf7_session_id]/document.pdf

    So the HTML might be as follows:
    <a href="/wp-content/uploads/pdfs/[wpcf7_session_id]/document.pdf" target="_blank" rel="noreferrer noopener">download</a>

    The session id will be created and stored in user’s cookies. Only that user will know the session id, so, they are the only ones who will have access to the filled PDF (assuming that you don’t have directory indexing enabled).

    Let me know if that helps or if you run into any issues.

Viewing 1 replies (of 1 total)
  • The topic ‘How to pass filename to new page and embed the pdf in new page?’ is closed to new replies.