0 votes
in SoSci Survey (English) by s219203 (310 points)
closed by s219203

I want only people aged 18+ to complete my survey. They know about this eligibility criteria upfront, but I would like to add an extra filter when I ask their age on page 3.

The age question is a text input where they can either enter a whole number or a range (e.g., 40-45). It is important that participants can provide a range instead of their exact age if they wish so.

The problem now arise where I want to create a filter so that the survey stops after they finish the 3rd page IF they are less than 18 years old (at that point they are directed to a page saying they do not meet the eligibility criteria). How do I create a rule for the age range so that the program knows that 16-20, for example, isn't an acceptable answer?

closed with the note: Resolved

1 Answer

0 votes
by SoSci Survey (302k points)

You'll have to decode the text response. A simple option would be to look for the first valid number. And while intval() would probably be sufficient, let's use a regular expression instead to have more fun:

$response = value('TX01_01');
if (!preg_match('/^(\\d+)/', $response, $matches)) {
    repeatPage();
}
$minAge = (int)$matches[1];

And the rest is a simple screenout:

if ($minAge < 18) {
    text('TX02');
    buttonHide();
    pageStop();
}
by s219203 (310 points)
Thanks for the codes!
It works with exact ages and ranges!

But I get an error message on the questionnaire page when it loads (i.e., before answers are given): "The function repeatPage() will only work as long as the page does not show any questions above."

Maybe I did not put it in the right stop? For now, I've put it as a single PHP code right under the age question. Note that the page contains multiple demographic questions, and I would like for the age question to be among them.

Thanks!
by SoSci Survey (302k points)
>  For now, I've put it as a single PHP code right under the age question.

That won't work :) Put it on top of the next page. value() does not know the answer before the respondents type them ... but your PHP code will run before the page is sent to the respondent.
by s219203 (310 points)
Works like a charm!
Thanks again!

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

...