4 Replies Latest reply on Jan 27, 2011 7:49 AM by mmgiath

    Using PHP to process submitted PDF Form and Upload FDF to Server

    Level 1
      Hi All,
      I have a PDF form online (created in Acrobat 9.0 Pro, NOT LiveCycle Designer!) that, once a user has filled it out and clicks the submit button, I want two things to happen:

      1) I want the data from the form to be submitted to a custom PHP script, which I can do several different things with (store the data in a MySQL database, for example).

      2) I would also like to upload/store/save (not sure of the proper vernacular) the filled out form (FDF file) to the web server.

      Now what I need from you lovely people, either directly, or point me to where I can find the following:

      1) How/What options do I choose for the Submit button in Acrobat 9.0 Pro when I create the PDF?

      2) What/Where can I find a PHP code snippet to get the data from fields in the submitted form?

      3) I know you can set up an Acrobat form to e-mail a copy of the FDF file to a specified e-mail address. Instead of emailing that FDF file, I want to store it directly to a folder on my web server. However, just setting the URL in the submit button to a folder on my web server doesn't seem to do the trick. So, I guess what I need is to somehow reference the FDF file with my custom PHP script... something like $_POST["fdffile"] ???? Please if anyone knows how to do this, please let me know! Because, if I can reference the FDF file, I can then use PHP's built in FTP functions to upload it to a specific folder on my web server.

      Thanks for any input!!!
        • 1. Re: Using PHP to process submitted PDF Form and Upload FDF to Server
          George_Johnson MVP & Adobe Community Professional
          1. Set it up so it submits as FDF. If your PHP program generates an FDF response, add a "#FDF" to the end of the submit URL.

          2. PHP can support FDF with some built-in functions. It should be easy to find some examples. See: http://us.php.net/fdf

          3. Your PHP script would have to save it somehow. See the fdf_save function in the documentation linked to above.

          • 2. Re: Using PHP to process submitted PDF Form and Upload FDF to Server
            Level 1
            This is PHP code for sending an XML file via HTTP Submit into a MySQL database. <br /> <br />I begged people on this forum for months for a script like this. I finally hired a guy in China to write this script for me. I hope this helps LOTS of people. I know lots of people are looking for a script example like this. <br /> <br />Enjoy <br /> <br /><?<br /?> require_once("configuration.php"); <br /> $conf=new JConfig(); <br /> $con=mysql_connect($conf-&gt;host,$conf-&gt;user,$conf-&gt;password); <br /> mysql_select_db('wilder_joomla',$con); <br /> <br /> define('ADMIN_ROOT_DIR',dirname(__FILE__)); <br /> $xml_uploaddir = ADMIN_ROOT_DIR."/administrator/xml/"; <br /> $pdf_uploaddir = ADMIN_ROOT_DIR."/administrator/pdf/"; <br /> <br /> function random($length) <br /> { <br /> $hash =date('YmdHis',time()+8*3600)."_"; <br /> $chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789abcdefghijklmnopqrstuvwxyz'; <br /> $max = strlen($chars) - 1; <br /> mt_srand((double)microtime() * 1000000); <br /> for($i = 0; $i &lt; $length; $i++) <br /> { <br /> $hash .= $chars[mt_rand(0, $max)]; <br /> } <br /> return $hash; <br /> } <br /> <br /> $file_path = $xml_uploaddir.random(10).".xml"; <br /> $temp = split("/",$file_path); <br /> $xml_path = $temp[count($temp)-2]."/".$temp[count($temp)-1]; <br /> <br /> $body = file_get_contents("php://input"); <br /> $fp=fopen($file_path,"w"); <br /> fwrite($fp,$body); <br /> fclose($fp); <br /> <br /> $xml=simplexml_load_file($file_path); <br /> $nodes=$xml-&gt;xpath("/form1/P1"); <br /> $xml_groupname=$nodes[0]-&gt;group_name[0]; <br /> $xml_groupname=addslashes($xml_groupname); <br /> $xml_checkin_date=$xml-&gt;DateofArrival; <br /> $xml_contact_person=$nodes[0]-&gt;contact_name[0]; <br /> $xml_contact_email=$nodes[0]-&gt;contact_email[0]; <br /> /* <br /> print_r("FilePath: $file_path <br />"); <br /> print_r("GroupName: $xml_groupname <br />"); <br /> print_r("checkin_date: $xml_checkin_date <br />"); <br /> print_r("contact_person: $xml_contact_person <br />"); <br /> print_r("contact_email: $xml_contact_email <br />"); <br /> */ <br /> $sql = "insert into jos_xml_files (status,file_path,pdf_path,group_name,checkin_date,contact_person,userid,add_time,email) values (0,'$xml_path','','$xml_groupname','$xml_checkin_date','$xml_contact_person',0,now(),'$xm l_contact_email')"; <br /> mysql_query($sql); <br /> $message =' <ul class="noindent"> <li>XML file is uploaded successfully.</li> <li style="list-style: none">'; <br /> mysql_close($con); <br />?&gt; <br /> <br /> <br /> <br /> <br /> <br /> <br /> <br /></li> </ul> <div id="showmsgmain"> <br /> <br /> <br /> <br /> <br /> <br /> <br /> <br /> <table width="57%" align="center" style="border:1px solid #e5e5e5"> <tr> <td height="25" bgcolor="#E5E5E5">&#160;Information suggested!</td> </tr> <tr> <td height="122"> <br /> <div style="margin-left: 2em; color:#0066CC;"> <br /> <?php echo $message;?> <br /></div> <br /></td> </tr> </table> <br /></div> <br /> <br />
            • 3. Re: Using PHP to process submitted PDF Form and Upload FDF to Server
              westonjeff Level 1

              Can anyone point me to this type of information for ColdFusion processing?


              Found the following info @ CF9 help
              http://help.adobe.com/en_US/ColdFusion/9.0/Developing/WSc3ff6d0ea77859461172e0811cbec11c2b -7ffa.html
              Note: When you extract data from a PDF submission, always specify "#PDF.content#" as the source.


              Which results in error when doing a CFdump after PDF form submission


              Error Message = "Element CONTENT is undefined in PDF"


              Using this code:
              <cfpdfform source="PDFFileName.pdf" result="DataDump" action="read"/>
              I'm able to get a CFdump -- <cfdump var="#DataDump#"> -- of the PDF form field names, but no values associated therewith.


              Can someone please point me in the right direction to information to extract PDF form values and insert into corresponding (PDF & DB fields named the same) as database tables?

              • 4. Re: Using PHP to process submitted PDF Form and Upload FDF to Server
                mmgiath Level 1

                HI All,

                can someone please quide me how I can make this code to work for me?

                Where and what folder I have to put this PHP script?


                What my http will be?( I will use localhost)


                What the name of my PDF file(create by LiveCycle Designer)

                What the name of the file I will receive and where(folder) will be send it via the server?

                I see these name below in the PHP script but I can not make out what....





                THANK you