You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何配置Google表单:提交前要求唯一密码(UNIQUE PASSCODE)及实现用户专属验证码(validation code)验证的步骤与表单、表格设置方法

Hey there! Let's tackle your two Google Forms needs with clear, actionable steps—no fancy external tools required, just built-in features and a bit of Google Apps Script for custom validation.

1. 设置Google表单提交前需输入唯一通用密码(UNIQUE PASSCODE)

This one's straightforward using Google Forms' built-in branching and data validation:

  • Open your Google Form, add a Short answer question titled something like "Enter the unique passcode", and mark it as required.
  • Click the three dots in the bottom-right corner of this question, then select Data validation.
  • In the validation rules, choose Text → Equals, then type your unique passcode (e.g., TeamAccess2024).
  • Add a custom error message like "Incorrect passcode—please try again" and save the validation.
  • To lock access to the rest of the form until the passcode is correct:
    1. Click the three dots again and select Go to section based on answer.
    2. For the correct passcode answer, choose Go to next section (make sure your main survey questions are in a separate section).
    3. For any incorrect input, select Go to section: [This section] to force the user to re-enter the passcode.
  • That's it! Users won't be able to access your main survey until they input the correct passcode.
2. 为每位用户分配专属验证码,输入正确后方可填写表单(关联Google Sheet配置)

This requires linking your form to a Google Sheet to track valid, unused codes, plus a small Apps Script to validate submissions in real-time:

Step 1: Prepare your verification code spreadsheet

  • Create a new Google Sheet. Name the first sheet something like "Verification Codes".
  • Set up headers in row 1:
    • Column A: Verification Code (fill this with unique codes for each user—you can generate random strings or use custom IDs)
    • Column B: Used (set all cells to FALSE initially; this will track if a code has been used)
    • Column C (optional): User Email (to link codes to specific users if needed)

Step 2: Configure the Google Form

  • Open your Google Form, add a Short answer question titled "Enter your unique verification code", mark it as required.
  • Click Extensions → Apps Script to open the script editor.
  • Replace the default code with this script (don't forget to update the Sheet ID and sheet name to match your spreadsheet):
    // Install the trigger to run validation on form submit
    function installTrigger() {
      ScriptApp.newTrigger('validateVerificationCode')
        .forForm(FormApp.getActiveForm())
        .onFormSubmit()
        .create();
    }
    
    function validateVerificationCode(e) {
      // Get the user's submitted code (assumes it's the first question in the form)
      var codeResponse = e.response.getItemResponses()[0];
      var inputCode = codeResponse.getResponse();
      
      // Connect to your verification code sheet
      var sheet = SpreadsheetApp.openById("YOUR_GOOGLE_SHEET_ID").getSheetByName("Verification Codes");
      var allData = sheet.getDataRange().getValues();
      var isCodeValid = false;
      var codeRowIndex = -1;
    
      // Check if the code exists and hasn't been used
      for (var i = 1; i < allData.length; i++) {
        if (allData[i][0] === inputCode && allData[i][1] === false) {
          isCodeValid = true;
          codeRowIndex = i + 1; // Spreadsheet rows start at 1
          break;
        }
      }
    
      // Handle invalid/used codes
      if (!isCodeValid) {
        // Show error feedback to the user
        e.response.setFeedback(FormApp.createFeedback()
          .setText("Invalid or already used verification code. Please check and try again.")
          .setInvalid(true)
          .build());
        // Delete the invalid submission from the form
        FormApp.getActiveForm().deleteResponse(e.response.getId());
      } else {
        // Mark the code as used in the sheet
        sheet.getRange(codeRowIndex, 2).setValue(true);
      }
    }
    
  • Save the script (name it something like "Form Code Validator"), then click Run → installTrigger. You'll need to authorize the script to access your form and sheet—follow the on-screen prompts (you may need to select "Advanced" → "Go to [Script Name]" to bypass the safety warning).
  • Back in your form, you can add optional data validation to the code question (e.g., limit text length) to guide users, but the script will handle the core validation.

Extra Tips

  • If you want to restrict codes to specific users, add a check in the script to match the submitted code with the user's email (you can get the respondent's email via e.response.getRespondentEmail() if you've enabled collecting emails in the form settings).
  • Regularly archive used codes in your sheet to keep the validation process fast.

内容的提问来源于stack exchange,提问作者Maricel Austria

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.04.30 13:02:37