我将如何以及在何处将这两个变量合并到 JavaScript 中?

How and where would I combine these two variable in JavaScript?

我将这段拼凑在一起的代码链接到此 PDF 中的一个操作按钮。它应该验证是否输入了所有必填字段,如果是,它将从文档中提取姓名和员工编号,并生成一封附有 PDF 的电子邮件。如果未通过这些检查,则会弹出一个警告用户缺少信息的窗口。

我遇到的问题是,当代码运行时,您可以绕过警告并仍然通过电子邮件发送文档。

如何调整它以停止,直到所有字段都得到回答?

期望"Pseudo code": 检查空白字段(获取经理的姓名)(获取经理的 EE 编号)。如果必填字段(复选框)和注释为空,则提醒用户。 如果不错,请从这些区域构建电子邮件主题行和文本...

这是目前的代码:

var emptyFields = [];

for (var i = 0; i < this.numFields; i++) {
    var f = this.getField(this.getNthFieldName(i));

    if (f.type != "button" && f.required) {
        if ((f.type == "text" && f.value == "") || (f.type == "checkbox" && f.value == "Off")) emptyFields.push(f.name);
    }
}

if (emptyFields.length > 0) {
    app.alert("Error! This checklist is incomplete:\n" + emptyFields.join("\n"));
}

// Build the subject line text from several fields form fields
var subj_text = getField("Weekly Management Critical Items:").valueAsString;
subj_text += ": " + getField("Manager Name").value;
subj_text += "- " + getField("Manager EE#").valueAsString;

// Send the email
mailDoc({
    cTo: "dennis.aikens@fedex.com",

    cSubject: subj_text,

    cMsg: "Hey Dennis, here's my checklist for this week. \r" + "Let me know if you have any questions. Thank you."
});

我知道它有点长,感谢您的阅读。

感谢您的宝贵时间和意见!

You should write down the clean control flow code... for now you can use that

var emptyFields = [];

for (var i = 0; i < this.numFields; i++) {
    var f = this.getField(this.getNthFieldName(i));

    if (f.type != "button" && f.required) {
        if ((f.type == "text" && f.value == "") || (f.type == "checkbox" && f.value == "Off")) emptyFields.push(f.name);
    }
}

if (emptyFields.length > 0) {
    app.alert("Error! This checklist is incomplete:\n" + emptyFields.join("\n"));
}else{
sendMail();
}


var sendMail = function(){
// Build the subject line text from several fields form fields
var subj_text = getField("Weekly Management Critical Items:").valueAsString;
subj_text += ": " + getField("Manager Name").value;
subj_text += "- " + getField("Manager EE#").valueAsString;

// Send the email
mailDoc({
    cTo: "dennis.aikens@fedex.com",

    cSubject: subj_text,

    cMsg: "Hey Dennis, here's my checklist for this week. \r" + "Let me know if you have any questions. Thank you."
});
}