在表单提交上下载pdf文件

时间:2015-05-11 20:15:03

标签: php jquery forms .htaccess

我有来自zoho crm的这个表格:

    <div id='crmWebToEntityForm' align='center'>
        <META HTTP-EQUIV ='content-type' CONTENT='text/html;charset = UTF-8'>
        <form action='http://crm.zoho.com/crm/WebToLeadForm' name=WebToLeads1041232000000749005 method='POST' onSubmit='javascript:document.charset="UTF-8"; return checkMandatery()' accept-charset='UTF-8'>  
            <input type='text' style='display:none;' name='xnQsjsdp' value='fbc5a29ead008c324c3a5bad0887e5bf1f95d083f11d4251a6f8aa5a236fd104'/> 
            <input type='hidden' name='zc_gad' id='zc_gad' value=''/>
            <input type='text' style='display:none;' name='xmIwtLD' value='eecaf957dfe7083c05ed797b5ed94512300831df6a467c5c0dca55e1967f2eae'/> 
            <input type='text'  style='display:none;' name='actionType' value='TGVhZHM='/>
            <input type='text' style='display:none;' name='returnURL' value='http://www.example.com/sucess-page' /> 
            <br>

            <table border=0 cellspacing=0 cellpadding='6' width=600 style='background-color:white;color:black'>
                <tr>
                    <td colspan='2' align='left' style='color:black;font-family:Arial;font-size:14px;'><strong>After Radical</strong></td>
                </tr>
                <br>
                <tr>
                    <td nowrap='nowrap' align='left'  style='font-size:12px;font-family:Arial;width:200px;'>Nombre </td><td style='width:250px;' ><input type='text' style='width:250px;'  maxlength='40' name='First Name' /></td>
                </tr>
                <tr>
                    <td colspan='2' align='center' style='padding-top: 15px;' >
                        <input style='font-size:12px;color:black' type='submit'  value='Submit' /> 
                        <input type='reset'  style='font-size:12px;color:black' value='Reset' /> </td>
                </tr>
            </table>
        </form>
    </div>

我想要实现的是,在提交时,用户在同一页面上下载PDF。我需要这样做以避免转到其他页面并让他们复制URL以下载文件而不使用/发送表单。

表单的实际行为是在提交时将用户发送到http://crm.zoho.com/crm/WebToLeadForm并加载回页面http://www.example.com/sucess-page,该页面是输入值。此页面与用户搜索表单的位置不同。

我试过改变这个:

form action='http://crm.zoho.com/crm/WebToLeadForm

到此:

form action='http://www.example.com/myfile.pdf

它可以在同一页面上下载PDF(之前我已将其添加到htaccess:AddType application/octet-stream .pdf)但是表单不会将用户信息发送到zoho crm管理。

知道怎么做到这一点?也许jQuery替代?

1 个答案:

答案 0 :(得分:0)

将表单发布到同一页面。然后在PHP代码中,检查表单是否已提交。如果有,请使用cURL将相同的数据发布到crm页面,然后回显PDF链接。

示例:

<form method="post" action="?">
   ...
</form>

然后检查表单是否已提交......

if ($_SERVER['REQUEST_METHOD'] == 'POST') {
     curlPostFunction();
     echo "<a href='http://example.com/example.pdf'>Click to download</a>";
}

阅读此链接,了解有关如何使用cURL创建POST功能的更多信息:This post

请注意,这只是一个基本示例 - 您的代码应根据您希望实现的安全性来包含更多检查。

相关问题