Important Update to Custom Scripting
SurveyGizmo's CustomScript Action now supports the LUA programming language. Visit our NEW Lua Scripting Resources!
Legacy Custom Scripting Language Deprecation Plans
- New accounts (created after October 29, 2018) will only have the option to use Lua in scripts.
- As of October 29, 2018 Custom Scripting Actions will default to Lua as the scripting type in the Custom Scripting Action for accounts created before this date. You will be able to switch to the Legacy Custom Scripting; though we highly encourage using Lua.
- In the long term, Legacy Custom Scripting Actions will be switched to read-only. The exact date on this is to be determined; we will send notifications well ahead of time.
This script will perform age verification based on the date of birth entered in an open text field. The qualifying age can be set in the script (18 years old, 21 years old, etc.) and if the user is not old enough, they will be disqualified. If they are old enough, the script does nothing and allows them to move forward through the survey. You can also customize the disqualification message using the script below.
Check it out in an example survey!!
This script uses the following question types or actions:
- Date (Textbox question with Date Validation)
- sgapiGetValue
- sgapiStrtotime
- sgapiDate
- sgapiDisqualify
The Script
The script example below will accept an age limit of 0 to 55 years old, and will disqualify your response if the date range equals less than 21 years of age from the current date.
%%textboxqid = 2; // Text field's Question ID %%agelimit = 21; // Age Limit - below this age will be disqualified %%qualifiedpage = 4; // The page ID where qualified respondents will start. %%msg = "I'm sorry, you are not old enough to take this survey. Thanks for your time!"; // Disqualification Message %%birthdate = sgapiGetValue(%%textboxqid); %%birthdate_unix = sgapiStrtotime(%%birthdate); %%today = sgapiDate("Y-m-d"); %%today_unix = sgapiStrtotime(%%today); %%validdate_unix = sgapiStrtotime('-'.%%agelimit.'years',%%today_unix); if (%%birthdate_unix > %%validdate_unix) { sgapiDisqualify(%%msg); } else { sgapiJumpToPage(%%qualifiedpage); }
In the script above you will need to customize specific variables in order to make the script work the way you'd like. There are two variables that are required to be changed for every survey you apply this code to, and then there is one optional variable you can change if you'd like.
Required Customizations
%%textboxqid - This variable will indicate the question ID of the date validated textbox where you collect birth date.
%%agelimit - The age limit you would like to set. Any response received with an age limit below this age (in years) will be disqualified. For example, if you do not want anyone under the age of 30 to fill out your survey, you'd want to use: %%agelimit = 30
%%qualifiedpage - The page to jump to when respondents are qualified.
Optional Customizations
%%msg - This message will display to the respondent who does not meet your age limit. You can choose to customize this further or leave the message as is.
Setup
Start by adding a date question asking your respondents to enter their birth date.
On the next page add a Custom Scripting action and paste in the script listed above. Customize your script to include your appropriate question IDs, page ID, age limit, and disqualification message.
Preview and Test your custom script to make sure the custom script is working properly.
Various Date Formats
If you need to be able to use this script based off of a date format that is not the standard US Date format (02/01/2003) then you'll need to remove the date validation from your textbox question. The script will still be able to run on the below date formats.
All of these formats represent the 1st of February, 2003
- mm/dd/yyyy - 02/01/2003
- mm/dd/yy - 02/01/03
- yyyy/mm/dd - 2003/02/01
- dd-mm-yyyy - 01-02-2003
- yy-mm-dd - 03-02-01
- yyyy-mm-dd - 2003-02-01
Scripting and Other Custom Solutions
We’re always happy to help you debug any documented script that is used as is. That said, we do not have the resources to write scripts on demand or to debug a customized script.
If you have customization ideas that you haven't figured out how to tackle, we're happy to be a sounding board for SurveyGizmo features and functionality ideas that might meet your customization. Beyond this, you might want to consult with someone on our Programming Services Team; these folks might have the scripting chops to help you to achieve what you are looking for!