在联系表7 Wordpress中提交后下载文件(on_sent_ok弃用) [英] Download File after submission in Contact Form 7 Wordpress (deprecated on_sent_ok)

查看:78
本文介绍了在联系表7 Wordpress中提交后下载文件(on_sent_ok弃用)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我希望用户在Wordpress中提交简单的联系表7后下载PDF文件。

I want the user to download a PDF file after submitting a simple Contact Form 7 in Wordpress.

我看到on_sent_ok已被弃用,将不被允许

I see that the on_sent_ok is deprecated and won't be allowed by the end of 2017 and should be replaced by DOM Events.

我在使用以下代码实现此目标时遇到问题:

I am having issues achieving this with the following code:

.htaccess文件:

.htaccess file:

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

functions.php:

functions.php:

function mycustom_wp_footer() {
?>
<script type="text/javascript">
document.addEventListener( 'wpcf7mailsent', function( event ) {
   if ( '1497' == event.detail.contactFormId ) {
      location( 'http://stagingarea2.craigsapsford.com/wpcontent/uploads/dlm_uploads/2017/11/Test-Document.pdf' );
   }
}, false );
</script>
<?php
}

我目前在哪里错了

推荐答案

请在您的functions.php中复制,粘贴和编辑此文件:

Please copy, paste and edit this in your functions.php:

add_action( 'wp_footer', 'mycustom_wp_footer' );

function mycustom_wp_footer() {
?>
<script type="text/javascript">
document.addEventListener( 'wpcf7mailsent', function( event ) {
if ( 'FORM ID' == event.detail.contactFormId ) {
    location = 'FILE PATH';
}
}, false );
</script>
<?php
}

以上之后,将以下内容粘贴到您的.htaccess文件中:

After the above, paste the following into your .htaccess file:

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

这对我有用。欢呼声

这篇关于在联系表7 Wordpress中提交后下载文件(on_sent_ok弃用)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆