Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

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

Engaged ,
May 09, 2016 May 09, 2016

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...

TOPICS
Acrobat SDK and JavaScript
5.5K
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

LEGEND , May 09, 2016 May 09, 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"}); 

Translate
Engaged ,
May 09, 2016 May 09, 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"}); 

}

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
May 09, 2016 May 09, 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

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Engaged ,
May 09, 2016 May 09, 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...

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
May 09, 2016 May 09, 2016
I've been having an issue on this forum with lag once I tag text with code syntax...

Welcome to the club When I have more than just a few lines to type, I usually paste my code, type all the text I want to type, and then as a last step select the code segments and use the syntax highlight function.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
May 09, 2016 May 09, 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"}); 

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Engaged ,
May 09, 2016 May 09, 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.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
May 09, 2016 May 09, 2016
LATEST

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".

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines