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

Windows 10环境下Google Forms限制重复链接提交实现方案咨询(新手级)

Absolutely! You can definitely set this up using Google Apps Script—no fancy tech background needed, even as a rookie. Let me break down exactly how to make your Google Form block duplicate restaurant links and show that specific error message when someone tries to submit one.

Step 1: Prep Your Form & Linked Sheet

First, make sure your Google Form has a Short answer field where people input the restaurant link (name it something clear like "Restaurant Link"). Also, confirm your form is linked to a Google Sheet (this happens automatically when you first create responses, but you can check by clicking the "Responses" tab in the form and looking for the green sheet icon).

Step 2: Open the Script Editor

In your Google Form, click the three dots in the top-right corner, then select "Script editor". This will open a new tab with a blank script file named Code.gs.

Step 3: Replace the Default Code with This Custom Script

Delete the default myFunction() code, then paste in this script. I’ve added comments so you know what parts to adjust for your setup:

function validateDuplicateLink(e) {
  // Get the form response data
  var response = e.response;
  var itemResponses = response.getItemResponses();
  
  // Replace this with the EXACT title of your link field in the form
  var linkFieldTitle = "Restaurant Link";
  var submittedLink = "";

  // Pull out the link the user just submitted
  for (var i = 0; i < itemResponses.length; i++) {
    var item = itemResponses[i];
    if (item.getItem().getTitle() === linkFieldTitle) {
      submittedLink = item.getResponse().trim();
      break;
    }
  }

  // If no link was entered, skip the check
  if (submittedLink === "") return;

  // Access the linked Google Sheet
  var sheet = SpreadsheetApp.getActiveSpreadsheet().getActiveSheet();
  
  // Adjust this range to match where your links are stored in the sheet:
  // The format is getRange(startRow, columnNumber, numberOfRows, numberOfColumns)
  // Example: If links are in column 2 and start at row 2 (row 1 is headers), use getRange(2, 2, sheet.getLastRow()-1, 1)
  var allSubmittedLinks = sheet.getRange(2, sheet.getLastColumn(), sheet.getLastRow()-1, 1).getValues();

  // Check if the submitted link already exists
  for (var j = 0; j < allSubmittedLinks.length; j++) {
    if (allSubmittedLinks[j][0].trim() === submittedLink) {
      // Throw the error message you want users to see
      throw new Error("That link has already been submitted");
    }
  }
}

// This triggers the validation every time someone submits the form
function onFormSubmit(e) {
  validateDuplicateLink(e);
}

Quick Tweaks You Need to Make:

  • Change linkFieldTitle to match the exact name of your link input field in the form (capitalization and spaces matter!).
  • Adjust the getRange line if your links aren’t in the last column of the sheet. For example, if your links are in column 3, replace sheet.getLastColumn() with 3.
Step 4: Set Up the Trigger to Run the Script Automatically

The script needs to run every time someone submits the form. Here’s how to set that up:

  1. In the Script Editor, click the clock icon (Triggers) on the left sidebar.
  2. Click Add Trigger in the bottom-right corner.
  3. Configure the trigger like this:
    • Choose which function to run: onFormSubmit
    • Choose which deployment to run: Head
    • Select event source: From form
    • Select event type: On form submit
  4. Click Save. You’ll need to authorize the script to access your form and sheet—this is safe (it’s your own script!). If Google says "Unverified app", click Advanced then Go to [Your Script Name] (unsafe) to complete the authorization.
Step 5: Test It Out

Submit a link through the form, then try submitting the same link again. You should see the error message "That link has already been submitted" pop up, and the duplicate response won’t be saved to the sheet.

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.05.07 16:58:13