0 votes
ago in SoSci Survey (English) by s090694 (110 points)
edited ago by SoSci Survey

Hello SoSci Survey Team,

We are currently working on a survey that includes 11 scenarios (dilemmas). For each one, an audio file is played first, followed on the next page by several questions, including an attention check (control question).

We’ve programmed this so that, depending on whether the German or English version is randomly selected, different questions are shown. For example, we use code like this directly after each attention check:

if (value('IF05') == 2) {
  $pt1 = 1;
} elseif (value('IF05') == 1) {
  $pt1 = 0;
}
elseif (value('IF16') == 2) {
  $pt1 = 1;
} elseif (value('IF16') == 1) {
  $pt1 = 0;
}

This pattern repeats for all 11 attention checks, with different variables ($pt1-$pt11)
In this setup, 0 means the question was answered correctly, 1 means it was answered incorrectly. The values 1 and 2 correspond to the actual response options.

What we would now like to achieve at the end of the survey is the following:

If a participant answers three or more attention checks incorrectly, they should not be redirected to the Clickworker page that shows the payment code. Instead, they should immediately see a message like this:

    In German: “Leider haben Sie zu viele Kontrollfragen falsch beantwortet und können die Studie nicht abschließen.”

    In English: “Unfortunately, you answered too many attention checks incorrectly and cannot complete the study.”
    Afterwards, the survey should simply end.

Participants who answered fewer than three attention checks incorrectly should proceed as normal to the Clickworker page, where they receive their code, and then to the final page that contains our closing text.

We have tried several approaches to achieve this, for example summing up and redirecting with goToPage(). Unfortunately, none of these solutions has worked reliably. In some cases we received errors such as “Undefined variable”, and in others participants were incorrectly redirected to the end page even when all attention checks were answered correctly.

We would greatly appreciate your support in finding a stable solution for SoSci Survey. Specifically, we’d like your advice on how best to count the number of incorrectly answered attention checks and then reliably decide whether to redirect the participant to the Clickworker page or terminate the survey with the appropriate message.

Thank you very much in advance for your help!

Best regards,

1 Answer

0 votes
ago by SoSci Survey (348k points)

I understand that some of the trouble arises from using different question in the two conditions. And I assume that the condition is the same throughout the questionnaire?

My recommendation would be to use a filter and calculate the errors based on the correct questions, for example:

if (condition1) {
  $errors = (value('IF05') == 2) + (value('IF06') == 1) + (value('IF07') == 2);
} else {
  $errors = (value('IF16') == 2) + (value('IF17') == 3) + (value('IF18') == 2);
}

As soon as you have to correct number, you can take care of the screenout.

if ($errors >= 3) {
  text('TX01');  // Display the text
}

And on the next page

if ($errors >= 3) {
  redirect(...);
}

Other options would include to store the errors in internal variables.

ago by s090694 (110 points)
I now have added these codes:
if (value('ZG01') == 1 || value('ZG01') == 2) {
  $errors =
    (value('IF05') == 2) +
    (value('IF10') == 2) +
    (value('IF02') == 2) +
    (value('IF09') == 1) +
    (value('IF01') == 2) +
    (value('IF03') == 1) +
    (value('IF04') == 1) +
    (value('IF11') == 1) +
    (value('IF07') == 1) +
    (value('IF06') == 2) +
    (value('IF08') == 1);
} else {
  $errors =
    (value('IF16') == 2) +
    (value('IF21') == 2) +
    (value('IF13') == 2) +
    (value('IF20') == 1) +
    (value('IF12') == 2) +
    (value('IF14') == 1) +
    (value('IF15') == 1) +
    (value('IF22') == 1) +
    (value('IF18') == 1) +
    (value('IF17') == 2) +
    (value('IF19') == 1);
}

put('IV01_01', $errors);

if ($errors >= 3) {
  if (value('ZG01') == 1 || value('ZG01') == 2) {
    text('AC01');
  } else {
    text('AC02');
  }
}  
and then this code on the next page right before the clickworker code:
if (value('IV01_01') >= 3) {
  goToPage('end');
}

I have stored the error as internal variable (IV01_01)

We have 4 surveys, they are the same but have a different order of the audios and questions. The weird thing is that the codes work in the first survey. When I answer all attention check questions correctly (less than three wrong), I get the Clickworker code. When I answer more than three questions wrong, I get a text the text that informs me I have not answered enough questions correctly and I am redirected to the last page without receiving a clickworker code. However, in surveys 2,3 and 4, when I answer the questions correctly, everything works but when I answer more than three incorrectly, I get a Questionnaire error, but weirdly on the page before I have added the code I added in the beginning and it says:
There is an error in the PHP code:

Questionnaire Error: Undefined variable $pt1
line: 3

PHP code

001 namespace s2survey\questionnaire\environment;
002
003 if ($pt1 + $pt2 + $pt3 + $pt4 + $pt5 + $pt6 + $pt7 + $pt8 + $pt9 + $pt10 + $pt11 > 3) {
004     if (value('ZG01') == 1) {
005         text('Leider haben Sie zu viele Kontrollfragen falsch beantwortet und können die Studie nicht abschließen.');
006     } elseif (value('ZG01') == 2) {

Questionnaire Error: Undefined variable $pt2
line: 3

PHP code

001 namespace s2survey\questionnaire\environment;
002
003 if ($pt1 + $pt2 + $pt3 + $pt4 + $pt5 + $pt6 + $pt7 + $pt8 + $pt9 + $pt10 + $pt11 > 3) {
004     if (value('ZG01') == 1) {
005         text('Leider haben Sie zu viele Kontrollfragen falsch beantwortet und können die Studie nicht abschließen.');
006     } elseif (value('ZG01') == 2) {

Questionnaire Error: Undefined variable $pt3
line: 3

PHP code

001 namespace s2survey\questionnaire\environment;
002
003 if ($pt1 + $pt2 + $pt3 + $pt4 + $pt5 + $pt6 + $pt7 + $pt8 + $pt9 + $pt10 + $pt11 > 3) {
004     if (value('ZG01') == 1) {
005         text('Leider haben Sie zu viele Kontrollfragen falsch beantwortet und können die Studie nicht abschließen.');
006     } elseif (value('ZG01') == 2) {

Questionnaire Error: Undefined variable $pt4
line: 3

PHP code

001 namespace s2survey\questionnaire\environment;
002
003 if ($pt1 + $pt2 + $pt3 + $pt4 + $pt5 + $pt6 + $pt7 + $pt8 + $pt9 + $pt10 + $pt11 > 3) {
004     if (value('ZG01') == 1) {
005         text('Leider haben Sie zu viele Kontrollfragen falsch beantwortet und können die Studie nicht abschließen.');
006     } elseif (value('ZG01') == 2) {

Questionnaire Error: Undefined variable $pt5
line: 3

PHP code

001 namespace s2survey\questionnaire\environment;
002
003 if ($pt1 + $pt2 + $pt3 + $pt4 + $pt5 + $pt6 + $pt7 + $pt8 + $pt9 + $pt10 + $pt11 > 3) {
004     if (value('ZG01') == 1) {
005         text('Leider haben Sie zu viele Kontrollfragen falsch beantwortet und können die Studie nicht abschließen.');
006     } elseif (value('ZG01') == 2) {

Questionnaire Error: Undefined variable $pt6
line: 3

PHP code

001 namespace s2survey\questionnaire\environment;
002
003 if ($pt1 + $pt2 + $pt3 + $pt4 + $pt5 + $pt6 + $pt7 + $pt8 + $pt9 + $pt10 + $pt11 > 3) {
004     if (value('ZG01') == 1) {
005         text('Leider haben Sie zu viele Kontrollfragen falsch beantwortet und können die Studie nicht abschließen.');
006     } elseif (value('ZG01') == 2) {

Questionnaire Error: Undefined variable $pt7
line: 3

PHP code

001 namespace s2survey\questionnaire\environment;
002
003 if ($pt1 + $pt2 + $pt3 + $pt4 + $pt5 + $pt6 + $pt7 + $pt8 + $pt9 + $pt10 + $pt11 > 3) {
004     if (value('ZG01') == 1) {
005         text('Leider haben Sie zu viele Kontrollfragen falsch beantwortet und können die Studie nicht abschließen.');
006     } elseif (value('ZG01') == 2) {

Questionnaire Error: Undefined variable $pt8
line: 3

PHP code

001 namespace s2survey\questionnaire\environment;
002
003 if ($pt1 + $pt2 + $pt3 + $pt4 + $pt5 + $pt6 + $pt7 + $pt8 + $pt9 + $pt10 + $pt11 > 3) {
004     if (value('ZG01') == 1) {
005         text('Leider haben Sie zu viele Kontrollfragen falsch beantwortet und können die Studie nicht abschließen.');
006     } elseif (value('ZG01') == 2) {

Questionnaire Error: Undefined variable $pt9
line: 3

PHP code

001 namespace s2survey\questionnaire\environment;
002
003 if ($pt1 + $pt2 + $pt3 + $pt4 + $pt5 + $pt6 + $pt7 + $pt8 + $pt9 + $pt10 + $pt11 > 3) {
004     if (value('ZG01') == 1) {
005         text('Leider haben Sie zu viele Kontrollfragen falsch beantwortet und können die Studie nicht abschließen.');
006     } elseif (value('ZG01') == 2) {

Questionnaire Error: Undefined variable $pt10
line: 3

PHP code

001 namespace s2survey\questionnaire\environment;
002
003 if ($pt1 + $pt2 + $pt3 + $pt4 + $pt5 + $pt6 + $pt7 + $pt8 + $pt9 + $pt10 + $pt11 > 3) {
004     if (value('ZG01') == 1) {
005         text('Leider haben Sie zu viele Kontrollfragen falsch beantwortet und können die Studie nicht abschließen.');
006     } elseif (value('ZG01') == 2) {

Questionnaire Error: Undefined variable $pt11
line: 3

PHP code

001 namespace s2survey\questionnaire\environment;
002
003 if ($pt1 + $pt2 + $pt3 + $pt4 + $pt5 + $pt6 + $pt7 + $pt8 + $pt9 + $pt10 + $pt11 > 3) {
004     if (value('ZG01') == 1) {
005         text('Leider haben Sie zu viele Kontrollfragen falsch beantwortet und können die Studie nicht abschließen.');
006     } elseif (value('ZG01') == 2) {

Questionnaire Error: Undefined variable $pt1
line: 13

PHP code

010     } elseif (value('ZG01') == 4) {
011         text('Unfortunately, you answered too many attention checks incorrectly and cannot complete the study.');
012     }
013 } elseif ($pt1 + $pt2 + $pt3 + $pt4 + $pt5 + $pt6 + $pt7 + $pt8 + $pt9 + $pt10 + $pt11 <= 3) {
014     return 'go:end';
015 }
016 return 'ok';

Questionnaire Error: Undefined variable $pt2
line: 13

PHP code

010     } elseif (value('ZG01') == 4) {
011         text('Unfortunately, you answered too many attention checks incorrectly and cannot complete the study.');
012     }
013 } elseif ($pt1 + $pt2 + $pt3 + $pt4 + $pt5 + $pt6 + $pt7 + $pt8 + $pt9 + $pt10 + $pt11 <= 3) {
014     return 'go:end';
015 }
016 return 'ok';

Questionnaire Error: Undefined variable $pt3
line: 13

PHP code

010     } elseif (value('ZG01') == 4) {
011         text('Unfortunately, you answered too many attention checks incorrectly and cannot complete the study.');
012     }
013 } elseif ($pt1 + $pt2 + $pt3 + $pt4 + $pt5 + $pt6 + $pt7 + $pt8 + $pt9 + $pt10 + $pt11 <= 3) {
014     return 'go:end';
015 }
016 return 'ok';

Questionnaire Error: Undefined variable $pt4
line: 13

PHP code

010     } elseif (value('ZG01') == 4) {
011         text('Unfortunately, you answered too many attention checks incorrectly and cannot complete the study.');
012     }
013 } elseif ($pt1 + $pt2 + $pt3 + $pt4 + $pt5 + $pt6 + $pt7 + $pt8 + $pt9 + $pt10 + $pt11 <= 3) {
014     return 'go:end';
015 }
016 return 'ok';

Questionnaire Error: Undefined variable $pt5
line: 13

PHP code

010     } elseif (value('ZG01') == 4) {
011         text('Unfortunately, you answered too many attention checks incorrectly and cannot complete the study.');
012     }
013 } elseif ($pt1 + $pt2 + $pt3 + $pt4 + $pt5 + $pt6 + $pt7 + $pt8 + $pt9 + $pt10 + $pt11 <= 3) {
014     return 'go:end';
015 }
016 return 'ok';

Questionnaire Error: Undefined variable $pt6
line: 13

PHP code

010     } elseif (value('ZG01') == 4) {
011         text('Unfortunately, you answered too many attention checks incorrectly and cannot complete the study.');
012     }
013 } elseif ($pt1 + $pt2 + $pt3 + $pt4 + $pt5 + $pt6 + $pt7 + $pt8 + $pt9 + $pt10 + $pt11 <= 3) {
014     return 'go:end';
015 }
016 return 'ok';

Questionnaire Error: Undefined variable $pt7
line: 13

PHP code

010     } elseif (value('ZG01') == 4) {
011         text('Unfortunately, you answered too many attention checks incorrectly and cannot complete the study.');
012     }
013 } elseif ($pt1 + $pt2 + $pt3 + $pt4 + $pt5 + $pt6 + $pt7 + $pt8 + $pt9 + $pt10 + $pt11 <= 3) {
014     return 'go:end';
015 }
016 return 'ok';

Questionnaire Error: Undefined variable $pt8
line: 13

PHP code

010     } elseif (value('ZG01') == 4) {
011         text('Unfortunately, you answered too many attention checks incorrectly and cannot complete the study.');
012     }
013 } elseif ($pt1 + $pt2 + $pt3 + $pt4 + $pt5 + $pt6 + $pt7 + $pt8 + $pt9 + $pt10 + $pt11 <= 3) {
014     return 'go:end';
015 }
016 return 'ok';

Questionnaire Error: Undefined variable $pt9
line: 13

PHP code

010     } elseif (value('ZG01') == 4) {
011         text('Unfortunately, you answered too many attention checks incorrectly and cannot complete the study.');
012     }
013 } elseif ($pt1 + $pt2 + $pt3 + $pt4 + $pt5 + $pt6 + $pt7 + $pt8 + $pt9 + $pt10 + $pt11 <= 3) {
014     return 'go:end';
015 }
016 return 'ok';

Questionnaire Error: Undefined variable $pt10
line: 13

PHP code

010     } elseif (value('ZG01') == 4) {
011         text('Unfortunately, you answered too many attention checks incorrectly and cannot complete the study.');
012     }
013 } elseif ($pt1 + $pt2 + $pt3 + $pt4 + $pt5 + $pt6 + $pt7 + $pt8 + $pt9 + $pt10 + $pt11 <= 3) {
014     return 'go:end';
015 }
016 return 'ok';

Questionnaire Error: Undefined variable $pt11
line: 13

PHP code

010     } elseif (value('ZG01') == 4) {
011         text('Unfortunately, you answered too many attention checks incorrectly and cannot complete the study.');
012     }
013 } elseif ($pt1 + $pt2 + $pt3 + $pt4 + $pt5 + $pt6 + $pt7 + $pt8 + $pt9 + $pt10 + $pt11 <= 3) {
014     return 'go:end';
015 }
016 return 'ok';

What is the mistake here?

Thank you so much in advance!
ago by SoSci Survey (348k points)
> Questionnaire Error: Undefined variable $pt1

Obviously from the error messages, you use a different code than above. The problem seems to be that the PHP variable $pt1 (and maybe not the others as well) are not defined in the respective PHP code block.
ago by s090694 (110 points)
But exactly that is the weird thing, I have not used a different code than above, I deleted the former codes that we used and pasted the exact same codes from the first questionnaire.
ago by SoSci Survey (348k points)
> I have not used a different code than above,

Okay, then please check "Compose Questionnaire" -> "Manage Questionnaires" if you have more than one questionnaire in the project? And please also check the tabs "PHP Functions" and "Internal Code" for $pt1.

Willkommen im Online-Support von SoSci Survey.

Hier bekommen Sie schnelle und fundierte Antworten von anderen Projektleitern und direkt von SoSci Survey.

→ Eine Frage stellen


Welcome to the SoSci Survey online support.

Simply ask a question to quickly get answers from other professionals, and directly from SoSci Survey.

→ Ask a Question

...