Have an idea?

Visit Sawtooth Software Feedback to share your ideas on how we can improve our products.

Javascript and pass-in fields

I have a survey with a pass in field (panelId) which is supposed to be a unique ID number for each survey respondent.

Is there a way, using javascript or any other way, to prevent duplicate IDs from taking the survey?
asked Nov 8, 2018 by kaitlan

1 Answer

0 votes
If you already know what the values passed in are going to be, you could use a password instead of a pass-in field.  Passwords can be passed into a survey URL the same way as regular pass-in fields, and have the ability to require uniqueness built in.

If you don't already know what the values are going to be, we'll need some unverified Perl.  Try the skip logic:

Begin Unverified Perl
# Parameters
my $pif = '';
my $table = '';
my $databaseName = '';
my $databaseUser = '';
my $databasePass = '';
my $databaseHost = '';
# IP Address
my $curr = GETVALUE($pif);
# Read database
my $dbh = DBI->connect('dbi:mysql:' . $databaseName . ':' . $databaseHost, $databaseUser, $databasePass);
my $sth = $dbh->prepare('SELECT `' . $pif . '` FROM `' . $table . '` WHERE `' . $pif . '` IS NOT NULL AND `' . $pif . '` <> ""');
my $count = 0;
while (my $row = $sth->fetchrow_arrayref()) {
    my $resp = $row->[0];
    if ($resp eq $curr) {
        if ($count > 1) {
# Return
return $count > 1;
End Unverified

Line 3 must be updated with the name of the pass-in field.

Line 4 must be updated with the name of the database table that stores this pass-in field.  This is probably "[STUDYNAME]_data1".

Lines 6-9 must be updated with your database credentials.  If you are hosting with us, you can find these credentials on hosting.sawtoothsoftware.com.
answered Nov 8, 2018 by Zachary Platinum Sawtooth Software, Inc. (121,625 points)
Alternatively, Lighthouse also permits cookie-based restarts in the password settings.  If the respondent is going to reenter on the same computer and no other respondents are going to use that computer, this could handle restarting for you.

(Laws may affect the legality of collecting cookies depending on the countries in which you are conducting the survey, including the GDPR.  Please be mindful of the relevant laws relating to collecting cookies.)
So I guess I'm confused. I added your unverified Perl  to the first question and when I tested the survey if I took it once and then tried to take it again I was redirected to the termination page...

Where in the survey should I have added the unverified Perl?

Thank you so much for your help
Did you end up changing the pass-in field into a password, or enabling cookie restarts?
I've had cookie based restart enabled but the pass in field is being passed in through a vendor, so I cant pre program the IDs.

If I allow respondents to define their own password and use the one click link, will the vendor be able to pass in their IDs?

And the survey is already in progress, will making this change cause any problems?

Thanks again for your help.
Passwords, including user-defined ones, can be passed in from a vendor in the exact same way as pass-in fields.


I haven't seen your study, but I did some testing with my own study where I re-published the study after converting a pass-in field into a user-defined password.  I didn't see any problems in my testing.  I even found that a respondent I created with a pass-in field could reenter the survey where they left off with the same link after I updated the study to use a password!