Download File after submission in Contact Form 7 Wordpress

你离开我真会死。 提交于 2019-12-04 20:18:11

I Found solution for your need,just follow below stops,it can not send mail,but works fine in local machine as per your requirement.

1) Just paste below code in your Additional Setting tab in contact form 7

demo_mode : on

on_sent_ok: "location = 'http://localhost/wordpress/wp-content/uploads/2017/08/pdf-sample.pdf';"

2) Put below code in your .htacess file, after [/IfModule] and below # END WordPress

<FilesMatch "\.(?i:pdf)$">
   ForceType application/octet-stream
   Header set Content-Disposition attachment
</FilesMatch>

the following code is working for me: I made it with javascript

function force_download( file ) {
    pdf = window.open(file, '', 'left=100,screenX=100');
    pdf.document.execCommand('SaveAs', 'null', 'myfile.pdf');
    pdf.close();
 }
 on_sent_ok: "force_download('pdf_url_here');"
Doron Davidowitz

If someone is looking for an up-to-date answer since in_sent_ok is being deprecated, instead we can use:

   <script>
    document.addEventListener( 'wpcf7mailsent', function( event ) {
    location = 'http://example.com/';
    }, false );
    </script>
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!