如何在提交按钮URL链接中包含Acrobat表单字段值

时间:2012-08-22 04:19:54

标签: php acrobat

我有一个在线Acrobat表单,用户填写并选择“提交”按钮。我已经定义了提交按钮,将完整的PDF文件发送到php程序,该程序只是将文件附加到电子邮件(phpMailer)并发送它。

我想要做的是发送静态表单名称,Acrobat表单中的客户名称字段值。因此,如果客户在Customer_Name字段中输入“John Doe”,我希望在提交中包含以下内容。

../ submit_pdf_form.php?form = New_Patient& Customer_Name = John Doe

这可以在Acrobat Pro X中使用吗?怎么做。

感谢

- PHP pgm源代码亮点 -

<?php
// what form are we sending
if (isset($_GET['form']))    { $form_type = $_GET['form']; }
//////////////////////////////////////////////////
//// this is the catching of the PDF
///////////////////////////////////////////////////
if(!isset($HTTP_RAW_POST_DATA)) 
{
    echo "The Application could not be sent. Please save the PDF and email it manually.";
    exit;
}
//////////////////////////////////////////
// Create PDF file with the filled data
//////////////////////////////////////////
$semi_rand = $form_type . time();
$pdf = $HTTP_RAW_POST_DATA;
$file = $semi_rand . ".pdf"; 
$handle = fopen($file, 'w+');
fwrite($handle, $pdf);   
fclose($handle);
/////////////////////////////////////////
require_once("\phpMailer\class.phpmailer.php");
...
set up mail
...
if(!$mail->AddAttachment($file))
    {
        echo "There was a problem attaching the pdf.";
        echo $mailer->ErrorInfo;
    }
 if(!$mail->Send()) {
    $error = "Error sending Email ".$mail->ErrorInfo; 
        echo $error; }

1 个答案:

答案 0 :(得分:1)

所以我终于想出了如何从adobe在线表单中获取信息。

<强> ACROBAT:

在Acrobat中创建一个按钮,在“动作”下选择“鼠标按下”,选择“动作运行JavaScript”,单击“添加”。在弹出的窗口中添加类似以下内容以获取表单字段并将表单提交到另一个程序以通过phpmailer发送电子邮件。这会将整个PDF文件发送到您的程序。

var name = getField("Shipper Name").valueAsString;  // get name field
name = name.replace(/(^[\s]+|[\s]+$)/g, '');        // trim spaces 
name = name.replace("'", "\\'");                    // change O'Neil to O\'Neil 
name = "'"+name+"'";
var email = getField("Shipper Email").valueAsString; // get email address
email = email.replace(/(^[\s]+|[\s]+$)/g, '');      // trim spaces from front and end
console.println("Your Email is Being sent to you and Dr. xxxxxx");
this.submitForm({
cURL: "../submit_pdf_form.php?form=New_Patient_Form&name="+name+"&email="+email,
cSubmitAs: "PDF"                                   // select form type PDF, FDF

});

有关Acrobat按钮定义的其他帮助,请参阅以下链接

http://www.w3.org/WAI/GL/WCAG20-TECHS/PDF15.html

<强> PHP 然后,您可以将信息提取到PHP程序中,如下所示发送:

<?php
include("class.phpmailer.php");        
// what form are we sending
$form_type = "";
$cust_name = "";
$cust_email = "";
if (isset($_GET['form']))  { $form_type = $_GET['form']; }
if (isset($_GET['name']))  { $cust_name = $_GET['name']; 
                           $temp = "\'";
                           $cust_name = str_replace($temp, "'", $cust_name);
                       }
if (isset($_GET['email'])) { $cust_email = $_GET['email']; }
//////////////////////////////////////////////////
//// this is the catching of the PDF
///////////////////////////////////////////////////
if(!isset($HTTP_RAW_POST_DATA)) 
{
    echo "The Application could not be sent. Please save the PDF and email it manually.";
    exit;
}
///////////////////////////////////////////////////
// Create PDF file with the filled data
///////////////////////////////////////////////////
$semi_rand = $form_type . "-" . date("s", time());
$pdf = $HTTP_RAW_POST_DATA;
$file = $semi_rand . ".pdf"; 
$handle = fopen($file, 'w+');
fwrite($handle, $pdf);   
fclose($handle);
///////////////////////////////////////////////////
//// this is the Emailing of the PDF
/////////////////////////////////////////////////// 
$mail_subject = "Patient Web Forms: " . $form_type;
$mail_message = "Patient submitted webform: \n" . $form_type . "\n Form from " . $cust_name . "\n Patient email: " . $cust_email;
$mail_from = "someone@comapny.com";
$mail_from_name = "Web Forms";
$mail_host = "smtp.company.net";
$username = "johndoe";
$password = "password"; 
$mail_to = "johndoe@company.com";                  // ---- use comma as separators
// --- look for localhost vs production ----
if ($_SERVER['HTTP_HOST'] == "localhost")             // -- test mode  ?
{
    $mail_to = "johndoe@testcom.com";
}
else
{
    $mail_to = "johndoe@company.com";
}
$message = "";

$mail = new PHPmailer(true);  // create a new object  (true = displays error messages) 
$mail->IsSMTP();          // enable SMTP
$mail->SMTPDebug = 0;         // debugging: 0 = off, 1 = errors and messages, 2 = messages only
// $mail->SMTPAuth = true;    // enable SMTP authentication
$mail->Port = 25;
$mail->Host = $mail_host;
$mail->Username = $username;  
$mail->Password = $password;           
$mail->SetFrom($mail_from, $mail_from_name);
$mail->Subject = $mail_subject;
$mail->Body = $mail_message;
$mail->AddAddress($mail_to);

if(!$mail->AddAttachment($file))
{
    $message = "There was a problem attaching the pdf.";
    echo "There was a problem attaching the pdf.";
    echo $mail->ErrorInfo;
    die;
}

if(!$mail->Send()) {
    $message = "Error sending Email ".$mail->ErrorInfo; 
} 
else 
{
    $message = "Form emailed to Dr Pearson's office";
}

$mail->ClearAddresses();
$mail->ClearAttachments();
unlink($file);              // delete the temporary pdf file then redirect to the success page
header("location: patients.php?msg=$message");

unlink($file);  //doubley make sure the temp pdf gets deleted
?>