I am trying to elicit a submission failure response (if not return a dynamically generated response) when a pdf is submitted via Adobe Reader or Foxit6 Reader. I have written code to accomplish this for Adobe, but Foxit only displays an alert box that states whether the submission was successful ("Your form submission was successful !") or not (I was unable to elicit this prompt). I'd like to manipulate the prompt's text if possible, otherwise present a message as a pdf. I even tried submitting the pdf to a non-existent url, and it still told me the submission was successful.
In the submission receiving code, I will be doing some validation & MYSQL querying and I want to be able to express any errors or redflags to the user.
As a side, I am using pdftk to create the dynamic pdf as it is already on the server and I would like to avoid using an additional library, although the process I am using does feel a bit overcomplicated.
Here's the flow:
1. User submits a pdf using a "Submit a form" bookmark with export format: HTML.
2. PHP:
* Collects the $_POST values
* Validates
* Saves to database
* Generates a response as an fdf
* A pdf with a single text field is fed the fdf using pdftk command to produce a new pdf
* Display new dynamic pdf via readfile();
My code works for Adobe, but not Foxit:
<?php
ob_start();
foreach($_POST as $key=>$val){
if(!$reader && strpos($key,"Content-Disposition:_form-data;_name")){
$reader="Foxit";
$regex='/\\\"(.*)\\\"\r\n\r\n(.*)\r\n/';
if(preg_match_all($regex,$val,$matches)){
$count=sizeof($matches[1]);
for($x=0; $x<$count; ++$x){
$array[$matches[1][$x]]=$matches[2][$x];
}
}
break;
}else{
$array["$key"]=$val;
if(!$reader){$reader="Adobe";}
}
}
// validation section, redflags are added to $alert
// connect to DB and INSERT IGNORE INTO mysql query, errors added to $alert
$file="Result_".date("YmdHis");
$template="Result.pdf";
$fdf="$file.fdf";
$pdf="$file.pdf";
$path=dirname(__FILE__);
$handle=fopen("$fdf","w");
if($handle!=false){
$fdf_content="%FDF-1.2\n%????\n1 0 obj\n<< \n/FDF << /Fields [ ";
$fdf_content.='<</T(Result)/V('.$alert.')>>';
$fdf_content.="] \n/F (".$pdf.") /ID [ <".md5(time()).">\n] >> \n>> \nendobj\ntrailer\n<<\n/Root 1 0 R \n\n>>\n%%EOF\n";
fwrite($handle,$fdf_content);
fclose($handle);
}
if(file_exists("$path/$fdf")){echo exec("chmod 777 $path/$fdf");}
if(is_executable("$path/$fdf")){exec("unblock pdftk \"$template\" fill_form \"$fdf\" output \"$pdf\" flatten; chmod 777 \"$pdf\"");}
if(file_exists("$path/$pdf")){
header('Content-type: application/pdf');
header("Content-Disposition: attachment; filename='$pdf'");
readfile("$pdf");
}
ob_end_flush();
?>
In the submission receiving code, I will be doing some validation & MYSQL querying and I want to be able to express any errors or redflags to the user.
As a side, I am using pdftk to create the dynamic pdf as it is already on the server and I would like to avoid using an additional library, although the process I am using does feel a bit overcomplicated.
Here's the flow:
1. User submits a pdf using a "Submit a form" bookmark with export format: HTML.
2. PHP:
* Collects the $_POST values
* Validates
* Saves to database
* Generates a response as an fdf
* A pdf with a single text field is fed the fdf using pdftk command to produce a new pdf
* Display new dynamic pdf via readfile();
My code works for Adobe, but not Foxit:
<?php
ob_start();
foreach($_POST as $key=>$val){
if(!$reader && strpos($key,"Content-Disposition:_form-data;_name")){
$reader="Foxit";
$regex='/\\\"(.*)\\\"\r\n\r\n(.*)\r\n/';
if(preg_match_all($regex,$val,$matches)){
$count=sizeof($matches[1]);
for($x=0; $x<$count; ++$x){
$array[$matches[1][$x]]=$matches[2][$x];
}
}
break;
}else{
$array["$key"]=$val;
if(!$reader){$reader="Adobe";}
}
}
// validation section, redflags are added to $alert
// connect to DB and INSERT IGNORE INTO mysql query, errors added to $alert
$file="Result_".date("YmdHis");
$template="Result.pdf";
$fdf="$file.fdf";
$pdf="$file.pdf";
$path=dirname(__FILE__);
$handle=fopen("$fdf","w");
if($handle!=false){
$fdf_content="%FDF-1.2\n%????\n1 0 obj\n<< \n/FDF << /Fields [ ";
$fdf_content.='<</T(Result)/V('.$alert.')>>';
$fdf_content.="] \n/F (".$pdf.") /ID [ <".md5(time()).">\n] >> \n>> \nendobj\ntrailer\n<<\n/Root 1 0 R \n\n>>\n%%EOF\n";
fwrite($handle,$fdf_content);
fclose($handle);
}
if(file_exists("$path/$fdf")){echo exec("chmod 777 $path/$fdf");}
if(is_executable("$path/$fdf")){exec("unblock pdftk \"$template\" fill_form \"$fdf\" output \"$pdf\" flatten; chmod 777 \"$pdf\"");}
if(file_exists("$path/$pdf")){
header('Content-type: application/pdf');
header("Content-Disposition: attachment; filename='$pdf'");
readfile("$pdf");
}
ob_end_flush();
?>