Search code examples
javascriptphppdfadobeacrobat

Submitted a PDF form to a PHP script only works in Adobe Reader XI


I have a PDF form that I want to submit to a remote php script. I thought I had it working but it seems only to be working when viewing the form in Adobe Reader XI. The submit button just doesn't seem to do anything in Adobe Reader 10 or in the Previewer on Mac. This is the javascript I have the button execute when it is clicked. It submits the entire PDF and also passes the email address and name for validation against a record in the database that the php script communicates with.

var email = getField("Your email").valueAsString;

var name = getField("Your name").valueAsString;  // get name field
name = name.replace(/(^[\s]+|[\s]+$)/g, '');        // trim spaces 
name = name.replace("'", "\\'");                    // change O'Neil to O\'Neil 
name = "'"+name+"'";

email = email.replace(/(^[\s]+|[\s]+$)/g, '');  

console.println("Your Plan is Being sent");

this.submitForm({
cURL: "http://example.com/thescript.php?name="+name+"&email="+email,
cSubmitAs: "PDF"});

Is there some syntax here that just isn't compatible with certain pdf readers? Any advice would be greatly appreciated.


Solution

  • A few aspects:

    • The script is OK so far, as it does work in Reader XI (and it also should work in Acrobat).

    • cSubmitAs: "PDF" requires that the filled form is saved. This is possible without limitations only in Reader XI; in earlier versions, you would have to assign Extended Rights to the form, in order to make it saveable.

    • You might activate the Console in Reader X, in order to see whether there are indeed error messages.

    • FORGET Preview.app!!! Preview.app does not support (Acrobat) JavaScript, and therefore, the script gets ignored. But even worse, when saving a filled form, Preview.app messes up the document in a way that it is no longer usable. If there is a higher chance that your users use Preview.app, you have to protect the form by make it non-fillable by default, and use a document-level script to make it fillable. In fact, that may be necessary if your form will also be used on iDevices etc.

    Aside from the issues mentioned, it might be necessary encode special characters in cURL.