3 Replies Latest reply on May 24, 2016 5:39 AM by Karl Heinz Kremer

    How to put field data into an array and pass it to a .php page on a webserver

    noscrodamus

      I have to pass pdf field data to a .php script I have on a webserver. I am assuming I will have to use ajax and json.

        • 1. Re: How to put field data into an array and pass it to a .php page on a webserver
          George_Johnson MVP & Adobe Community Professional

          The easiest way is to set up the form to submit to the PHP script using the same method and format as an HTML form would. So reading data submitted by a PDF form can be as simple as it is from an HTML form.

           

          The difference is in the type of response that you'd send back. The best method is to return an FDF response that includes something the provides some feedback to the user. For example, it could cause a pop-up message to be displayed or fill a field in the form. This is the same idea as AJAX (and FDF can be considered analogous to JSON as they're both structured data interchange formats used for asynchronous client/server communication), and was the method PDF forms used before AJAX was ever available for use with a browser.

           

          Note that this won't work with most non-Adobe PDF viewers since they don't support submitting to a web server, or correctly handling an FDF response, or both. It will work with the desktop versions of Adobe Reader/Acrobat, even when not using in a web browser. I wouldn't recommend this as something for the general public to use, but if you have a set of users that you can compel to use such a system, it can work well.

          • 2. Re: How to put field data into an array and pass it to a .php page on a webserver
            noscrodamus Level 1

            Thanks for the response George!

             

            I have about 4-5 forms I need users to fill out. The end game is for the user to submit the first form, then have the contents of the first form fill out the second form.

            I've already created a function for importing data to the PDF using FDF from my webserver. Works Great. The problem is going the other way (Exporting from PDF to webserver). I would prefer not to use FDF as it requires much slicing and dicing of all the extra characters. I would prefer to throw all form data into an array and pass it back to my webserver - as I already have a html/php form on my webserver to accept the array.

             

            You said it's just like an HTML form. How would I reference the individuals fields ( textfields, checkboxes, dropdowns etc.)

            Is Javascript the only option I have to do something like this?

             

            Thanks!

            • 3. Re: How to put field data into an array and pass it to a .php page on a webserver
              Karl Heinz Kremer Adobe Community Professional

              Take a look a the Doc.submitForm() API documentation: Acrobat DC SDK Documentation - Doc.submitForm()

              The "cSubmitAs" parameter allows you to select - among other formats - "HTML", which will create a standard HTML forms submission, just like from a web form. All you do in PHP is use the $_POST array to reference the field data.

               

              And no, JavaScript is not the only way to do this: You can use the standard "Submit a form" action triggered by e.g. a button:

               

              2016-05-24_08-37-42.png

              Keep in mind that besides FDF, there is also XFDF to submit data to the PHP script. XML is usually much easier to handle than FDF (but then again, in PHP, a HTML forms submission is built right into the system).

              1 person found this helpful