从谷歌表单中检索HREF链接

时间:2013-11-22 03:30:39

标签: google-apps-script

function onSubmit(e) {
  var myemail = "duffysuchard@gmail.com"  // please, replace myemail by your email 
  try{
    var formResponse = e.response;//get the form response
    var editResponseUrl = formResponse.getEditResponseUrl(); //get the individual form url just in case the respondent needs to edit its anwers later
    var itemResponses = formResponse.getItemResponses();// get all item questions and anwers
    var itemResponse
    var title
    var response
    for (var i = 0; i < itemResponses.length; i++) {    // iterate for all form items
      itemResponse = itemResponses[i];
      title = itemResponse.getItem().getTitle().toUpperCase(); // get the question title. In our form can be EMAIL or NAME
      response =  itemResponse.getResponse().toString();  // get the corresponding answer
      if(title.indexOf("EMAIL", 0) != -1){   // if the title is "EMAIL"
        var email = response.toLowerCase();  // get it
      }
      else if (title.indexOf("NAME", 0) != -1){  // if the title is "NAME"
        var name = response.toLowerCase(); // get it
      }
    }
    var subject ="Confirmation";    // subject of the message you're assembling
    var message = "Dear " + name + ",\n\n"; // body of the message you're assembling
    message += "Thanks for answering our survey. \n\n"; // body of the message you're assembling
    message += "Click on the link bellow to edit your previous answers:\n\n"; // body of the message you're assembling
    message += editResponseUrl + "\n\n"; // body of the message you're assembling
    MailApp.sendEmail(email, subject, message, {replyTo:myemail,cc:myemail}); // send the message
  }
  catch(e) {             // if something wrong happens 
    MailApp.sendEmail(myemail, "Error in Auto replying to contact form submission.", e.message); // tell me
  }
}

1 个答案:

答案 0 :(得分:0)

在实际需要Spreadsheet form submit event时,您似乎正在使用Form submit event

在文档(Understanding Events)中,显示了每个事件的结构:

电子表格表单提交事件:

  • 范围
  • namedValues

表格提交活动:

  • 响应

您需要在表单中创建不在电子表格中的脚本。