0

i use the following code in my functions php to reach a download after contact form 7 submission. but it is not working

//contact form 7 Download white paper//

add_action( 'wp_footer', 'redirect_cf7' );

function redirect_cf7() {
?>
<script type="text/javascript">
document.addEventListener( 'wpcf7mailsent', function( event ) {
   if ( '4265' == event.detail.contactFormId ) { // Sends sumissions on form 4265 to the first thank you page
    location = '/wp/wp- 
content/uploads/2018/06/file.pdf';
     } else if ( '4266' == event.detail.contactFormId ) { // Sends submissions on form 1070 to the second thank you page
        location = '/wp/wp- 
content/uploads/2018/06/file2.pdf';
     }
    else {
     //do nothing
         }
}, false );
</script>
<?php
}

You have any ideas why it does not work?

best regards

1

Try the following and replace [DOMAIN] by your own domain.

//contact form 7 Download white paper//
add_action( 'wp_footer', 'redirect_cf7' );

function redirect_cf7() {
    ?>
    <script type="text/javascript">
        document.addEventListener( 'wpcf7mailsent', function( event ) {
            if ( '4265' == event.detail.contactFormId ) { // Sends sumissions on form 4265 to the first thank you page
                var pdfLink = '[DOMAIN]/wp/wp-content/uploads/2018/06/file.pdf';
            } else if ( '4266' == event.detail.contactFormId ) { // Sends submissions on form 1070 to the second thank you page
                var pdfLink = '[DOMAIN]/wp/wp-content/uploads/2018/06/file2.pdf';
            }
            else {
                //do nothing
            }
            jQuery.get(pdfLink, (data) ->
              window.location.href = jQuery(this).attr('href');
            )
        }, false );
    </script>
    <?php
}
  • thanks for your answer. Also with your changes it is not working. There is still no redirect after submitting the form. :-( – tom84 Oct 8 '18 at 9:59
  • Check this out. I think it is already solved here. – Karun Oct 9 '18 at 5:41
0

CF7 has the ability to email PDFs after submission built in already.

If you go to the Mail tab for the form, and check the "Use Mail (2), you can write a reply email after the form in submitted.

In the "File Attachments" text area, enter in:

[your-file]
uploads/2018/10/the-media-library-url-for-PDF.pdf

I would copy that code exactly to that field with the correct file path - that's how I have gotten it to work

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.