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

Dealing with empty form fields in email

New Here ,
Sep 06, 2024 Sep 06, 2024

I'm a total beginner and I have "elementary shcool" level of Javascript knowledge.

With google's help, I was able to get a button, that sends an email with custom subject and body using data from the fields in the form, working.

Where I have a problem is when checking if a field is empty.  The form has 3 field names.

First one is always filled out so I don't need to check. 2nd and 3rd ones however I need to check if they are empty so I can include them in the email or not.

When I use the code below the script doesn't even run when I press the button which leads me to think that there's an error and that's why it doen't run.

Besides of "valueAsString" I have also tried just "value" but I get the same result.

I also tried the === instead of the ==

Any ideas what I'm doing wrong?

 

The code I use is: 

var RR2Name = this.getField("RR1Name").valueAsString;
var RR2Name = this.getField("RR2Name").valueAsString;
var emailSubject;

if (RR2Name =="") {
emailSubject = RR1Name + " form"
} else {
emailSubject = RR1Name + " and " + RR2 + " form"
}

 

TOPICS
JavaScript , PDF forms
612
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 ,
Sep 06, 2024 Sep 06, 2024

You named both variables 'RR2Name' and in the script you use RR1Name, so change one to RR1Name.

There may be other issue, it is best to post full script if you still have issues.

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
New Here ,
Sep 07, 2024 Sep 07, 2024

My appologies Nesa. They are in fact RR1Name and RR2Name. When I was copying from my work computer I mistyped and I can't find a way to correct my post.

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 ,
Sep 07, 2024 Sep 07, 2024

Check the JavaScript console for errors.

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
New Here ,
Sep 07, 2024 Sep 07, 2024

I don't see any errors. I'll post the whole code when I get back home. Maybe it's something else. 

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 ,
Sep 07, 2024 Sep 07, 2024

If a field value is a single space, Is is empty?  If so, then your code won't detect it. 

Maybe you should expand the empty field test so that misc white space is part of the empty test. 

 

 

var RR1Name = this.getField("RR1Name").valueAsString;
var RR2Name = this.getField("RR2Name").valueAsString;
var emailSubject;
// Create regular expression for detecting text 
// composed solely of 0 or more white spaces, i.e., blanks.
var rgEmpty = /^\s*$/;

if (rgEmpty.test(RR2Name)) {
emailSubject = RR1Name + " form"
} else {
emailSubject = RR1Name + " and " + RR2 + " form"
}

 

 

You might also be interested in this article:

https://acrobatusers.com/tutorials/dynamically-setting-submit-e-mail-address/

 

Thom Parker - Software Developer at PDFScripting
Use the Acrobat JavaScript Reference early and often

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 ,
Sep 07, 2024 Sep 07, 2024
LATEST

You need to post the full code or share the file. This is not enough information to know what's wrong.

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