简体   繁体   English

Google表单/ Google表格的JavaScript验证

[英]JavaScript Validation for Google Forms/Google Sheet

It's been a while since I've done JavaScript, but I could just be having issues with Google Scripts... 自从我完成JavaScript已有一段时间了,但是我可能在Google脚本方面遇到了问题...

I'm trying to validate a response to a Google Form. 我正在尝试验证对Google表单的回复。 Essentially, we send out a form asking for a name, email and code word given at the end of a webinar. 本质上,我们发送一个表格,要求在网络研讨会的末尾提供姓名,电子邮件和密码。 If the user responds correctly, we want to send them an email with a URL to a form with ethics credit. 如果用户正确回答,我们希望向他们发送一封电子邮件,其中包含指向具有道德信用的表格的URL。 If incorrect, we want to send them an email with their incorrect response. 如果不正确,我们希望向他们发送电子邮件,并提供错误的回复。 Currently, I can pull all the data, but for some reason, cannot change valid to false...So far, I know that everything before "var valid = false" works. 目前,我可以提取所有数据,但是由于某种原因,无法将有效值更改为false ...到目前为止,我知道“ var valid = false”之前的所有内容都可以正常工作。 Can someone tell me what I'm doing wrong here? 有人可以告诉我我在做什么错吗? Thanks. 谢谢。

/* before this section - gets values from separate Google sheet
   and gets other responses from the Google Form */

var submission = itemResponses[2].getResponse(); // gets code word response from form

var newSubmission = submission.toLowerCase().trim(); // format submission;

var valid = false;
var month = "";
var url = "";


for(var i; i < range.length; i++) {
   if(range[i][1] == newSubmission) { // range is the range in the spreadsheet. 
                                      // [i][1] is the second col of selection.
     valid = !valid;
     month += range[i][0];
     url += range[i][2];
     break;
   }
}

After this, it just sends the email. 此后,它仅发送电子邮件。 I do receive emails, but they always come as the false response... 我确实收到了电子邮件,但它们总是作为错误的回复来的。

如果要让循环开始更改此行,则必须将值设置为i:for(var i; i <range.length; i ++){by for(var i = 0; i <range.length; i ++){

Yeah, sorry, I forgot to take this down. 是的,对不起,我忘了记下来。 You were correct, ClemT. 你是正确的,ClemT。 Here's the full code, if anyone would like to view it. 如果有人想查看的话,这是完整的代码。

https://github.com/AJax2012/google-form-validate-with-sheet https://github.com/AJax2012/google-form-validate-with-sheet

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM