0 Replies Latest reply on Mar 12, 2009 8:58 AM by cyan_studios

    SubmitAs: "PDF", PHP not parsing field data

    cyan_studios Level 1
      My goal is this: <br />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). <br /> <br />My method is this: <br />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. <br /> <br />My results so far: <br />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. <br /> <br />Now some code. <br />Here is what's on my button (where I suspect something is missing.) <br /> <br />var myDoc = event.target; <br />myDoc.submitForm({ <br /> cURL: "http://localhost/forms/time/save.php#PDF", <br /> cSubmitAs: "PDF", <br /> cPermID: myDoc.docID[0], <br /> cInstID: myDoc.docID[1], <br /> cUsageRights: submitFormUsageRights.RMA <br />}); <br /> <br />The PHP code: <br /> <br /><?php<br /><br />DumpArray("HEADERS", emu_getallheaders());<br />DumpArray("REQUEST",$_REQUEST);<br />$body = file_get_contents("php://input");<br /><br />$foreman = $_POST['forecatch']; #user's name<br />$curdate = $_POST['mon']; # date field<br /><br />$filestring = "$foreman-$curdate.pdf";<br />$filestring = str_replace( ' ', '', $filestring ); <br />$filestring = str_replace( ',', '', $filestring ); <br />copy( 'timetemplate.pdf', $filestring );<br />$fp = fopen( $filestring, 'wb' );<br />fwrite( $fp, $GLOBALS[ 'HTTP_RAW_POST_DATA' ]  );<br />fclose( $fp );<br /><br />echo '<br><br />File successfully written. <a href="/forms/time/">Click here to view your file directory.</a><br>';<br />echo $foreman . "<br>";<br />echo $curdate . "<br>";<br />echo $filestring . "<br>";<br /><br /># Function DumpArray <br />##########################################################<br />function DumpArray($ArrayName,&$Array) {<br /><br />foreach ($Array as $Key=>$Value){<br />    echo "$Key:$Value\n";<br />  } # End of foreach ($GLOBALS as $Key=>$Value)<br />} # End of function DumpArray <br />#################################################<br /><br />function emu_getallheaders() {<br />foreach($_SERVER as $h=>$v)<br />if(ereg('HTTP_(.+)',$h,$hp))<br />  $headers[$hp[1]]=$v;<br />  $headers["CONTENT_TYPE"]=$_SERVER["CONTENT_TYPE"];<br />  return $headers;<br />}<br /><br />?> <br /> <br />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. <br /> <br />Conversely, the regular button with the code returns a perfect .pdf in every way that I need it, except the file name. <br /> <br />I'm expecting this to be one line of javascript in the button that needs changing/added. <br /> <br />Added: <br />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.