在 Contact Form 7 Wordpress 中提交后下载文件
Download File after submission in Contact Form 7 Wordpress
我正在尝试制作一种提供功能的表单,例如当用户输入姓名和电子邮件时,PDF 文件就会自动开始下载。
当我在提交按钮的附加设置选项卡中应用此代码时,它会像这样重播错误消息。
我目前在本地机器上工作,我知道联系表 7 邮件选项卡中有错误,但不知道如何解决?
"There was an error trying to send your message. Please try again later."
这是我的联系表 7 代码:
<label> Name
[text* your-name] </label>
<label> Email
[email* your-email] </label>
[submit "Download Now"]
这是我在附加设置中编写的代码,用于在提交表单时直接下载 PDF 文件
on_sent_ok: "location = 'http://localhost/wordpress/wp-content/uploads/2017/08/pdf-sample.pdf';"
以下代码对我有用:我用 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');"
我找到了满足您需要的解决方案,只需按照以下停止,它无法发送邮件,但根据您的要求在本地机器上工作正常。
1) 只需将下面的代码粘贴到联系表 7 的“附加设置”选项卡中
demo_mode : on
on_sent_ok: "location = 'http://localhost/wordpress/wp-content/uploads/2017/08/pdf-sample.pdf';"
2) 将以下代码放入您的 .htacess 文件中,在 [/IfModule] 之后和 # END WordPress 下方
<FilesMatch "\.(?i:pdf)$">
ForceType application/octet-stream
Header set Content-Disposition attachment
</FilesMatch>
如果有人正在寻找 up-to-date 答案,因为 in_sent_ok
已被弃用,我们可以使用:
<script>
document.addEventListener( 'wpcf7mailsent', function( event ) {
location = 'http://example.com/';
}, false );
</script>
我正在尝试制作一种提供功能的表单,例如当用户输入姓名和电子邮件时,PDF 文件就会自动开始下载。
当我在提交按钮的附加设置选项卡中应用此代码时,它会像这样重播错误消息。
我目前在本地机器上工作,我知道联系表 7 邮件选项卡中有错误,但不知道如何解决?
"There was an error trying to send your message. Please try again later."
这是我的联系表 7 代码:
<label> Name
[text* your-name] </label>
<label> Email
[email* your-email] </label>
[submit "Download Now"]
这是我在附加设置中编写的代码,用于在提交表单时直接下载 PDF 文件
on_sent_ok: "location = 'http://localhost/wordpress/wp-content/uploads/2017/08/pdf-sample.pdf';"
以下代码对我有用:我用 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');"
我找到了满足您需要的解决方案,只需按照以下停止,它无法发送邮件,但根据您的要求在本地机器上工作正常。
1) 只需将下面的代码粘贴到联系表 7 的“附加设置”选项卡中
demo_mode : on
on_sent_ok: "location = 'http://localhost/wordpress/wp-content/uploads/2017/08/pdf-sample.pdf';"
2) 将以下代码放入您的 .htacess 文件中,在 [/IfModule] 之后和 # END WordPress 下方
<FilesMatch "\.(?i:pdf)$">
ForceType application/octet-stream
Header set Content-Disposition attachment
</FilesMatch>
如果有人正在寻找 up-to-date 答案,因为 in_sent_ok
已被弃用,我们可以使用:
<script>
document.addEventListener( 'wpcf7mailsent', function( event ) {
location = 'http://example.com/';
}, false );
</script>