These forums are now Read Only. If you have an Acrobat question, ask questions and get help from one of our experts.

SubmitAs: "PDF", PHP not parsing field data

cyanstudios
Registered: May 6 2008
Posts: 81

My goal is this:
Set up a button that allows the user to save the .PDF with a single click that automatically names the file and places it in a specific directory (in this case, a directory named after the user).

My method is this:
Create a standard button and use a submitForm() function to send the currently filled PDF to a php script. This php script takes the "foreman" (user name) field and turns it into variable, as well as the current date field. The php script copies the basic template pdf, renames it according to the variables, and fills it with all of the data.

My results so far:
Everything works fine except the php script does not seem to be receiving the field data for naming the file or defining the variables. However, it IS filling the new PDF with all the data that I need. So it's receiving data for one operation, but not for naming the file.

Now some code.
Here is what's on my button (where I suspect something is missing.)

var myDoc = event.target;
myDoc.submitForm({
  cURL: "http://localhost/forms/time/save.php#PDF",
  cSubmitAs: "PDF",
  cPermID: myDoc.docID[0],
  cInstID: myDoc.docID[1],
  cUsageRights: submitFormUsageRights.RMA
});

The PHP code:
<?php
 
DumpArray("HEADERS", emu_getallheaders());
DumpArray("REQUEST",$_REQUEST);
$body = file_get_contents("php://input");
 
$foreman = $_POST['forecatch']; #user's name
$curdate = $_POST['mon']; # date field
 
$filestring = "$foreman-$curdate.pdf";
$filestring = str_replace( ' ', '', $filestring ); 
$filestring = str_replace( ',', '', $filestring ); 
copy( 'timetemplate.pdf', $filestring );
$fp = fopen( $filestring, 'wb' );
fwrite( $fp, $GLOBALS[ 'HTTP_RAW_POST_DATA' ]  );
fclose( $fp );
 
echo '<br>
File successfully written. <a href="/forms/time/">Click here to view your file directory.</a><br>';
echo $foreman . "<br>";
echo $curdate . "<br>";
echo $filestring . "<br>";
 
# Function DumpArray 
##########################################################
function DumpArray($ArrayName,&$Array) {
 
foreach ($Array as $Key=>$Value){
    echo "$Key:$Value\n";
  } # End of foreach ($GLOBALS as $Key=>$Value)
} # End of function DumpArray 
#################################################
 
 
function emu_getallheaders() {
foreach($_SERVER as $h=>$v)
if(ereg('HTTP_(.+)',$h,$hp))
  $headers[$hp[1]]=$v;
  $headers["CONTENT_TYPE"]=$_SERVER["CONTENT_TYPE"];
  return $headers;
}
 
?>

I'm under the impression that the PHP is the way it needs to be. I know this because when I change the form's button to an HTTPSubmit, and give it a straight submission to save.php, I get a .pdf file that is correctly named. Obviously though, it's 0 bytes and useless upon trying to open it.

Conversely, the regular button with the code returns a perfect .pdf in every way that I need it, except the file name.

I'm expecting this to be one line of javascript in the button that needs changing/added.

My Product Information:
LiveCycle Designer, Windows
cyanstudios
Registered: May 6 2008
Posts: 81
I've figured that this has something to do with encoding and a conflict. It seems that in order to parse the data, I need to submit the field data in an encoding that's different from the overall data that I'm placing in the copy.