This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
en:create:php-filters [21.09.2019 19:15] – [Using else] sarah.lahmeyer | en:create:php-filters [19.03.2021 10:02] (current) – sophia.schauer | ||
---|---|---|---|
Line 1: | Line 1: | ||
- | + | ====== | |
- | ====== | + | |
- | + | ||
If the participant' | If the participant' | ||
Line 16: | Line 13: | ||
**Tip**: If you separate respondents into a control group and an experimental group ([[en: | **Tip**: If you separate respondents into a control group and an experimental group ([[en: | ||
- | ===== Example: Yes-No-Filters ===== | ||
- | |||
+ | ===== Example: Yes-No Filters ===== | ||
+ | |||
Before explaining filters and their function in depth, we will show you a quick-and-dirty solution for those of you who don't have the time. A Yes-No-Filter is probably the most used filter. | Before explaining filters and their function in depth, we will show you a quick-and-dirty solution for those of you who don't have the time. A Yes-No-Filter is probably the most used filter. | ||
Line 24: | Line 21: | ||
**Example 2:** If a questionee answers " | **Example 2:** If a questionee answers " | ||
+ | |||
==== Preparations ==== | ==== Preparations ==== | ||
Line 43: | Line 41: | ||
-9 = no answer | -9 = no answer | ||
- | So the ID of the variable is “PT01”, the answer code for “yes” is “1” and the code for “no” is “2”. Ideally you have configured the question to demand a complete answer (tab //Check for completion// | + | So the ID of the variable is “PT01”, the answer code for “yes” is “1” and the code for “no” is “2”. Ideally, you have configured the question to demand a complete answer (tab //Check for completion// |
**Attention: | **Attention: | ||
- | ===== Entering a php-code | + | |
+ | ===== Entering a PHP Code ===== | ||
The filter should be entered as a //PHP code// when **Creating A Questionnaire**, | The filter should be entered as a //PHP code// when **Creating A Questionnaire**, | ||
Line 53: | Line 52: | ||
**Important: | **Important: | ||
- | ===== Frequent | + | ===== Frequent |
If you can handle the PHP function '' | If you can handle the PHP function '' | ||
- | ==== Whether to display | + | ==== Whether to Display |
The following PHP code uses '' | The following PHP code uses '' | ||
Line 77: | Line 76: | ||
- | ==== Show different questions | + | ==== Show Different Questions |
Depending on a previous answer (or a group assignment, e.g. by [[: | Depending on a previous answer (or a group assignment, e.g. by [[: | ||
Line 116: | Line 115: | ||
- | ==== Vary content | + | ==== Vary Content |
Instead of questions, contents, e.g. stimuli, can also be varied. More about this in the chapter [[: | Instead of questions, contents, e.g. stimuli, can also be varied. More about this in the chapter [[: | ||
Line 129: | Line 127: | ||
</ | </ | ||
- | ==== Skip pages ==== | ||
+ | ==== Skip Pages ==== | ||
When **compiling the questionnaire**, | When **compiling the questionnaire**, | ||
Line 147: | Line 145: | ||
**Tip**: Read the rest of this chapter. It's worth it! | **Tip**: Read the rest of this chapter. It's worth it! | ||
- | ===== The keyword IF ===== | ||
+ | ===== The Keyword IF ===== | ||
Filters are programmed through IF-THEN-ELSE-relations in the element // | Filters are programmed through IF-THEN-ELSE-relations in the element // | ||
Line 168: | Line 166: | ||
} | } | ||
- | ===== Show or do not show questions | + | |
+ | ===== Show or do not Show Questions | ||
Line 192: | Line 191: | ||
{{fig.filters.jump.png? | {{fig.filters.jump.png? | ||
- | ===== Conditions ===== | ||
+ | ===== Conditions ===== | ||
A condition is always put into round brackets (). It may be complied with (the condition will return “true”) or not (“false”). | A condition is always put into round brackets (). It may be complied with (the condition will return “true”) or not (“false”). | ||
Line 208: | Line 207: | ||
**Tip**: To check if a variable has the value 1 __or__ 2, read [[en: | **Tip**: To check if a variable has the value 1 __or__ 2, read [[en: | ||
- | ===== Skip pages ===== | ||
+ | ===== Skip Pages ===== | ||
Back to the simple example: On page 1 of the questionnaire we ask the question AB01 (selection about the income). Our goal is to ask the questions EK01 and EK 02 only if the questionee chose option 1 in AB01. | Back to the simple example: On page 1 of the questionnaire we ask the question AB01 (selection about the income). Our goal is to ask the questions EK01 and EK 02 only if the questionee chose option 1 in AB01. | ||
Line 221: | Line 220: | ||
**Tip**: You don't need to enter the questions themselves as PHP-code - you can still drag-and-drop them from the selection list into the page ([[php# | **Tip**: You don't need to enter the questions themselves as PHP-code - you can still drag-and-drop them from the selection list into the page ([[php# | ||
- | ===== Assigning | + | |
+ | ===== Assigning | ||
For page 3 in the questionnaire you will need a page ID. Let's use “tvconsum”. We need this to be able to jump to this page using '' | For page 3 in the questionnaire you will need a page ID. Let's use “tvconsum”. We need this to be able to jump to this page using '' | ||
Line 229: | Line 229: | ||
{{scr.filters.page_ident.png? | {{scr.filters.page_ident.png? | ||
- | ==== Using as little | + | |
+ | ==== Using as Little | ||
{{scr.filters.simple.page1.png? | {{scr.filters.simple.page1.png? | ||
Line 237: | Line 238: | ||
{{scr.filters.simple.page3.png? | {{scr.filters.simple.page3.png? | ||
- | ==== Using as much PHP-code as possible ==== | ||
+ | ==== Using as much PHP Code as Possible ==== | ||
Usually you will try to use PHP-code only where needed – like above. Just because questionnaires can be written much quicker in PHP, this manual often uses the following form. Contentwise, | Usually you will try to use PHP-code only where needed – like above. Just because questionnaires can be written much quicker in PHP, this manual often uses the following form. Contentwise, | ||
Line 265: | Line 266: | ||
**Important**: | **Important**: | ||
- | ==== Tips about the function value() ==== | ||
+ | ==== Tips about the Function value() ==== | ||
* There are two easy ways to find out which value will be saved in an answer: The **Variables listing** and the debug mode while testing the questionnaire ([[questionnaire|Create a Questionnaire]]). | * There are two easy ways to find out which value will be saved in an answer: The **Variables listing** and the debug mode while testing the questionnaire ([[questionnaire|Create a Questionnaire]]). | ||
Line 272: | Line 273: | ||
* All functions specific to SoSciSurvey are listed and explained at [[functions|PHP functions]]. | * All functions specific to SoSciSurvey are listed and explained at [[functions|PHP functions]]. | ||
- | ===== Instruction blocks ===== | ||
+ | ===== Instruction Blocks ===== | ||
The example shows a curly bracket following the if-condition ('' | The example shows a curly bracket following the if-condition ('' | ||
Line 292: | Line 293: | ||
</ | </ | ||
- | ===== Step by step ===== | + | ===== Step by Step ===== |
This paragraph explains the programming of a small filter step by step. | This paragraph explains the programming of a small filter step by step. | ||
- | ==== The filter question | + | |
+ | ==== The Filter Question | ||
Back to using IF-THEN-conditions as filter questions: Every question can become a filter question, when its answer is used as a condition. First, create any question. | Back to using IF-THEN-conditions as filter questions: Every question can become a filter question, when its answer is used as a condition. First, create any question. | ||
Line 321: | Line 323: | ||
Tip**: The option **This question demands a complete answer** should in general be used very sparse. But as filters need to decide things upon this answer, it is recommended to use the option for filter questions. | Tip**: The option **This question demands a complete answer** should in general be used very sparse. But as filters need to decide things upon this answer, it is recommended to use the option for filter questions. | ||
- | ==== Filters about the selection | + | |
+ | ==== Filters about the Selection | ||
To use TF01 as filter question, you need the command '' | To use TF01 as filter question, you need the command '' | ||
Line 339: | Line 342: | ||
All questionees – regardless of their answer to the filter question TF01 – will see the question AB01. Did the questionnee answer “no” to TF01, he will only see one question on page 2: AB01. Did he answer “yes”, he will see four questions in total on page 2. | All questionees – regardless of their answer to the filter question TF01 – will see the question AB01. Did the questionnee answer “no” to TF01, he will only see one question on page 2: AB01. Did he answer “yes”, he will see four questions in total on page 2. | ||
+ | |||
==== Using else ==== | ==== Using else ==== | ||
Line 352: | Line 356: | ||
question(' | question(' | ||
} | } | ||
- | question(' | + | question(' |
- | ===== Skip pages ===== | + | ===== Skip Pages ===== |
If not using any '' | If not using any '' | ||
Line 400: | Line 405: | ||
**Tip**: Ever since SoSci Survey Version 2.2.02 empty pages will be skipped by default. Thereby you often times don't have to worry about empty pages. | **Tip**: Ever since SoSci Survey Version 2.2.02 empty pages will be skipped by default. Thereby you often times don't have to worry about empty pages. | ||
- | ===== The right ID ===== | + | |
+ | ===== The Proper | ||
The example uses a selection. A simple selection will save just one value, the chosen option. This can be called with '' | The example uses a selection. A simple selection will save just one value, the chosen option. This can be called with '' | ||
Line 436: | Line 442: | ||
The chapter [[filter-itemcount|At least one item]] shows some tricks on how to use scales in filters. | The chapter [[filter-itemcount|At least one item]] shows some tricks on how to use scales in filters. | ||
- | ===== Screenout: Filter | + | ===== Screenout: Filter |
In case your survey has a certain target group, you might want to filter unsuitable participants and dismiss them after some screening questions. To do so, ask the screening questions early in the questionnaire and use a common filter afterwards. | In case your survey has a certain target group, you might want to filter unsuitable participants and dismiss them after some screening questions. To do so, ask the screening questions early in the questionnaire and use a common filter afterwards. | ||
Line 454: | Line 460: | ||
**Tip**: By repeating a filter you are able to check different variables. Using boolean operators you can check several variables in one filter ([[filter-boolean|Linking Multiple Conditions]]). | **Tip**: By repeating a filter you are able to check different variables. Using boolean operators you can check several variables in one filter ([[filter-boolean|Linking Multiple Conditions]]). | ||
- | ===== Tips about filters | + | ===== Tips about Filters |
Filters are very flexible tools. You can nest them if needed. You can check complex conditions. We will explain more in further chapters (see below). | Filters are very flexible tools. You can nest them if needed. You can check complex conditions. We will explain more in further chapters (see below). | ||
Line 471: | Line 477: | ||
* After having jumped through pages using '' | * After having jumped through pages using '' | ||
- | ===== Complex filters | + | ===== Advanced Filters |
Most filters can be sufficiently programmed using the above programming basics. But not all. The following chapters will show you solutions for more complex filters: | Most filters can be sufficiently programmed using the above programming basics. But not all. The following chapters will show you solutions for more complex filters: | ||
Line 480: | Line 486: | ||
* [[filter-itemcount|At Least One Item Selected]] - Loops | * [[filter-itemcount|At Least One Item Selected]] - Loops | ||
* [[filter-items|Use Selected Items in Another Question]] - Arrays | * [[filter-items|Use Selected Items in Another Question]] - Arrays | ||
+ | |||