Products
GG网络技术分享 2025-03-18 16:12 0
I am trying to make one form which give functionality like when user enter name and email,then PDF file starts download automatically.
And while i am applying this code in additional setting tab on submit button,it replay the error message like this.
I am currently working in local machine, i know error is in contact form 7 mail tab,but don\'t know how to fix it?
\"There was an error trying to send your message. Please try again later.\"
Here is my contact form 7 code:
<label> Name[text* your-name] </label>
<label> Email
[email* your-email] </label>
[submit \"Download Now\"]
Here is code that i write in Additional Setting for download PDF file directly when form is submitted
on_sent_ok: \"location = \'http://localhost/wordpress/wp-content/uploads/2017/08/pdf-sample.pdf\';\"
图片转代码服务由CSDN问答提供
感谢您的意见,我们尽快改进~
功能建议我正在尝试创建一个表单,提供用户输入名称和电子邮件等功能,然后PDF文件自动开始下载 。</ p>
当我在提交按钮的其他设置选项卡中应用此代码时,它会重播这样的错误消息。</ p>
我目前正在工作 在本地机器上,我知道错误是联系表格7邮件标签,但不知道如何解决?</ p>
“尝试发送邮件时出错。请再试一次 以后。“</ p>
这是我的联系表格7代码:</ p>
&lt; label&gt; 姓名[text * your-name]&lt; / label&gt;
&lt; label&gt; 电子邮件
[email * your-email]&lt; / label&gt;
[提交“立即下载”]
</ code> </ pre>
以下是我写的代码 提交表单时直接下载PDF文件的附加设置</ p>
on_sent_ok:“location =\'http:// localhost / wordpress / wp-content / uploads / 2017/08 / pdf -sample.pdf\';“</ code> </ pre>
</ div>
网友观点:
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 : onon_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\');\\\"
###
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>
</div>
Demand feedback