javascriptformspdfadobe-javascript

PDF Form Submit to email


I have a PDF form, it's very basic, only 4 fields. I need to add a button and have it send an email out based on data entered into the form.

Currently I have the following.

var's for the four fields.

var cName = this.getField("Name").value; 
var cNumber = this.getField("Phone").value; 
var cEMail = this.getField("Email").value; 
var erAgent = this.getField("Agent").value;

Email structure.

var erBody = cName + "has entered their details and with to be contacted on " +  cNumber + " for phone or can be EMailed at " + cEMail;
var erSub = cName + " details";
var erEmailURL = "mailto:" + erAgent + "&subject=" + erSub + "&body=" + erBody;

When I add a submit function, i can't get any of them to work. I have added a few below.

app.mailMsg({cURL: encodeURI(erEmailURL)});

app.mailMsg({cURL:"mailto:" + erAgent + "&subject=" + erSub + "&body=" + erBody});

Neither of these seem to work. I have also tried.

this.submitForm({cURL: encodeURI(erEmailURL), cSubmitAs:"XML", cCharSet:"utf-8"});
this.submitForm({cURL:"mailto:" + erAgent + "&subject=" + erSub + "&body=" + erBody, cSubmitAs:"XML", cCharset:"utf-8"});

Again, seemingly not working.

Can anyone point out my mistake? or point me in the right direction.

Thanks for reading. :)


Solution

  • There is a mischmasch of Acrobat JavaScript and web browser JavaScript/URI assembly.

    Have a closer look at the mailForm() and related methods in the Acrobat JavaScript documentation (which is part of the Acrobat SDK documentation, downloadable from the Adobe website).

    In short, the correct syntax for mailForm() in your context is in this line:

    this.mailForm({
    cTo: erAgent,
    cSubject: erSub,
    cMsg: erBody
    })
    

    You'd have to adjust accordingly.

    If for whatever reason you insist on following an URL-coded path, you would use the getURL() method.