Skip to main content
MADink_Designs27
Inspiring
May 9, 2016
Answered

Use this.submitForm() to submit emails based on user entry

  • May 9, 2016
  • 2 replies
  • 5736 views

I'm trying to use the this.submitForm() function to be able to allow users to send the form instead of the built in method due to different emails dependent on user entry of a text field.

Below works—except that I want the pdf to be sent instead of the fdf data. I'm trying to get it to function using the cSubmitAs: input parameter, but can't seem to get the syntax right...

if(manufacturer.value == "Manufacturer A") {

this.submitForm(

  "mailto:name@address.com;name2@address.com?&cc=name@address.com;name2@address.com&subject=New Service Request Submittal"

  );

}

else {

this.submitForm(

  "mailto:name@address.com;name2@address.com?subject=New Service Request Submittal"

  );

}

After doing a little research, I've come up with:

var manufacturer = this.getField("manufacturer");
var nEmail = "mailto:name@address.com;name2@address.com?&cc=name@address.com;name2@address.com&subject=New Service Request Submittal";
var allEmail = "mailto:name@address.com;name2@address.com?subject=New Service Request Submittal";

if(manufacturer.value == "Manufacturer A") {
this.submitForm({nEmail, cSubmitAs: "PDF"});
}
else {
this.submitForm({allEmail, cSubmitAs: "PDF"});
}

But I seem to be getting JavaScript errors no matter what I try...

This topic has been closed for replies.
Correct answer gkaiseril

When using "{" an "}" in a method indicates you are specifying the parameter name and then the value and not just the positional parameter  value. So the "this.submitForm" statements should read:

this.submitForm({cTo: nEmail, cSubmitAs: "PDF"}); 

and

this.submitForm({cTo:allEmail, cSubmitAs: "PDF"}); 

2 replies

gkaiserilCorrect answer
Inspiring
May 9, 2016

When using "{" an "}" in a method indicates you are specifying the parameter name and then the value and not just the positional parameter  value. So the "this.submitForm" statements should read:

this.submitForm({cTo: nEmail, cSubmitAs: "PDF"}); 

and

this.submitForm({cTo:allEmail, cSubmitAs: "PDF"}); 

MADink_Designs27
Inspiring
May 9, 2016

Thanks, while I technically found out what I was doing wrong, I wanted to give you the credit instead.

Examples I found before were using "cURL:" while you put "cTo:" could I basically put anything after "c" and have it still work with the first parameter? I was assuming it was the same as the "cSubmitAs" parameter and that it needed to be exactly that to work.

Karl Heinz  Kremer
Community Expert
Community Expert
May 9, 2016

No, you need to use the parameter names as specified in the API documentation (see the link I provided earlier). Different methods use different parameters. Doc.submitForm() uses "cURL" as it's parameter name. Doc.mailDoc() or Doc.mailForm() (see here: Acrobat DC SDK Documentation) use "cTo".

MADink_Designs27
Inspiring
May 9, 2016

It seems I just needed to add the parameter "cURL:" before the variable in the array. Then everything's peachy.

var manufacturer = this.getField("manufacturer"); 

var nEmail = "mailto:name@address.com;name2@address.com?&cc=name@address.com;name2@address.com&subject=New Service Request Submittal"

var allEmail = "mailto:name@address.com;name2@address.com?subject=New Service Request Submittal"

if(manufacturer.value == "Manufacturer A") { 

this.submitForm({cURL: nEmail, cSubmitAs: "PDF"}); 

}

else { 

this.submitForm({cURL; allEmail, cSubmitAs: "PDF"}); 

}

Karl Heinz  Kremer
Community Expert
Community Expert
May 9, 2016

That is correct. You do however have a typo in your sample code - you are using ";" instead of ":".

To give you some background: You are passing an object to the Doc.submitForm() function as it's first (and only) parameter. An object in JavaScript uses key/value pairs (the property name and the property value). So by leaving out the key (or property name), you created a corrupt object that did not actually have a valid cURL property.

See here for more information about the Doc.submitForm() method with a description of all parameters: Acrobat DC SDK Documentation

MADink_Designs27
Inspiring
May 9, 2016

Thanks! Yes that's a typo in the sample code. I have it correctly written in the real code.

I've been having an issue on this forum with lag once I tag text with code syntax...