How can I prefill a PDF PDF form using the url query string (or better method)?

I need to fill out a PDF web form that will be publicly available with data taken from the URL query string. I don't want the user to be able to edit anything on the form - just print or save it.

I understand this is not the safest way as they can edit the query string to change the data. Is there a safer way?

I am currently trying to do this using the simplest way: pdf form and javascript on form.

The code follows, but has not been tested properly. I am wondering if this is the correct approach?

 // This code was taken from:
 // http://blogs.adobe.com/pdfdevjunkie/2009/12/populating_pdf_form_fields_fro.html
 // Accessed: June 15, 2015

 //only run the script if the PDF file is being viewed in a browser window
 if (this.external)
 {
     //The whiteList defines which fields are permitted to be changed by the URL.
     //If you want all fields to be changed, leave the array empty as in "[]"
     //whiteList = ["Name", "Address", "City", "State", "ZipCode"]
     whiteList = []

     //get the parameters portion of the URL and unescape it so we get the spaces and punctuation back
     parametersString = this.URL.substring(this.URL.indexOf("?")+1)
     //only run the script if there are parameters
     if (parametersString.length > 0)
     {
         //create an array of key/value pairs
         parameters = parametersString.split("&")
         //loop through the array...
         for each (parameter in parameters)
         {
             //create a 2 element array for each parameter as [key, value]
             kvPair = parameter.split("=")
             //set the field named "key" to "value"
             fieldName = unescape(kvPair[0])
             if (whiteList.length > 0)
             {
               if (whiteList.indexOf(fieldName) > -1)
               {
                   this.getField(fieldName).value = unescape(kvPair[1])
               }
             }
             else
             {
                this.getField(fieldName).value = unescape(kvPair[1])
             }
       }
   }
}

      

+3


source to share





All Articles