These forums are now Read Only. If you have an Acrobat question, ask questions and get help from one of our experts.

Create a submit button using JS for form tracking

acrobat3d
Registered: Jun 30 2006
Posts: 5

I am trying to add a button to a form so that the user can submit their fillable form data via Acrobat.com
 
I am using a script as follows (replacing with a real address. But I continually get JS errors (unterminated literal string at line 57) in Acrobat X when I try to attach this JS to a submit button.
The code however is good as far as I can tell
 
Can anyone figure out why and how to fix?
 

JAVASCRIPT:
//@@SUBMITURL "mailto:<email>?subject=Submitting Completed Form&body=Instructions to add this form to a responses file:\n1. Double-click the attachment.\n2. Acrobat will prompt you to select a responses file.&ui=false"
 
/**************************************************************
AdobePatentID="B643"
**************************************************************/
var AdobePatentID = "AdobePatentID=\"B643\"";
 
// initiate some constants
var METADATA_ANNOT_NAME     = "adhocFormState";
var PROP_RESPONDENT_NAME    = "respondentName";
var PROP_RESPONDENT_EMAIL   = "respondentEmail";
 
var currentDoc;
if (typeof(xfa) == "object")
    currentDoc = event.target;
else
    currentDoc = this;
 
// Only on Viewer/Reader older than 9.0, we'll do the following tasks.
var bAnonymous = false;
var bContinue = true;
if (app.viewerVersion < 9.0) {
 
    // show the email/name dialog if not anonymous
    if (!bAnonymous && !currentDoc.dynamicXFAForm) {
        var result = currentDoc.askUserIdentity(currentDoc);
        if (result == null) 
            bContinue = false;
        else {    
            var annot = currentDoc.getAnnot(0, METADATA_ANNOT_NAME);
            if (annot != null) {
                var arrProps = new Array();
                arrProps = annot.contents.split(";");
                currentDoc.setProperty(arrProps, PROP_RESPONDENT_NAME, result.name);
                currentDoc.setProperty(arrProps, PROP_RESPONDENT_EMAIL, result.email);
                annot.contents = arrProps.join(";");
            }
        }
    }
 
    // show the select client dialog
    if (bContinue) {
        var result = currentDoc.askEmailClient(currentDoc);
        if (result == null)
            bContinue = false;
        else if (!result.send)  {
            app.execMenuItem("SaveAs");
            bContinue = false;
        }
    }
}
 
// submit the form
if (bContinue) {
    var rawURL = "<email>?subject=Submitting Completed Form&body=Instructions to add this form to a responses file:\n1. Double-click the attachment.\n2. Acrobat will prompt you to select a responses file.&ui=false";
    var submitURL;
    if (app.viewerVersion < 9.0)
        submitURL = "mailto:" + rawURL;
    else
        submitURL = "mailto:" + escape(rawURL);
    currentDoc.submitForm({
        cURL: submitURL,
        cSubmitAs: "PDF"
    });
}

Web marketing and community development

thomp
Expert
Registered: Feb 15 2006
Posts: 4411
I think that the current issue may be that a hard CR is being inserted at line 55. Are you copying this from a text file? The hard CR is most likely being picked up on the copy side.

This code is a copy of the code from a submit button on a "Distributed" form. You do know that most of this is undocumented? and you may have some additional issues. Those functions are only available in a document that was already setup for distribution and the submit to Acrobat.com properties are setup in the Advanced Metadata under "AcrobatAdhocWorkflow/1.0". Both of these elements are necessary to get Acrobat 9 or X to submit to Acrobat.com.


Thom Parker
The source for PDF Scripting Info
www.pdfscripting.com
Very Important - How to Debug Your Script