Translations of this page:

Problem Solution for Filters

Filters or filter questions traditionally are a challenge for project leaders without programming experiences. Of course it is helpful to read the instructions on filters first: Filters and Conditional Question.

It is especially frustrating if filters don't work and you don't know what to do. This chapter describes how to find out mistakes in a fast way.

The Most Common Problems

A filter of a questionaire usually includes 2 parts:

  1. A filter question that is answered by the respondents. The answer determines how the questionaire proceeds, e.g. if another questions is displayed or not.
  2. PHP code, technically the filter that in particular determines what will happen.

Top 1

Please check first, if the filter is located on the same page as the filter question (e.g. at the top the filter question and below the PHP code including the filter).

This can't work: data of each page of a questionaire is always processed from top to down – and only at the end the results (of a questionaire page) is send to the browser of the respondent. This means: if a filter question is displayed at the respondent, the filter has already been active. The answer of the respondent, which shall be read out through value() is not available at this Moment – the filter has nothing to react on.

The solution is easy: place a PHP-code as a filter on the next page of the questionaire.

If question and filter have to be on the same page, the following chapter may help: Directly show questions for the selection of a certain option

Top 2

The command value() may include a wrong variable value.

For value() you always need the value of a variable in the data set, not the value of a question or an item (also if both often are the same).

Solution: The correct values of variables are listed in the variable overview. Before an after the value the command value() requires single (') or double quotation marks ("), e.g. value('AB01_01').

Top 3

Is the question shown although the filter should exclude it? Or is the question even shown twice? If the warning “Items in the following question are already displayed further up on this page. This almost inevitably leads to data loss”?

Please take into consideration that “roping-in” a question into a questionaire page using Drag & Drop has the same effect like the use of question() (e.g. in a filter). Maybe you roped the question in in addition to the question() command.

Solution: remove the question from the page (Delete or move questions), so that it is only integrated through the question() command.

Detect Failures

The result of the function value() is not the one you have expected? Or the filter is not jumping to the point you thought? Filter and programming is no rocket science. The Server will do what has been written in the PHP code step by step.

To understand it the debug mode will be very helpful: to get into the debug mode, start the questionaire with Create a questionaire with the yellow arrow (Start the questionaire in the debug mode). The debug mode has three different aspects compared to the normal questionaire mode:

  1. The identification of each question is shown in squared brackets.
  2. In the upper right there is a button “debug information”. Click it to see the debug information of the current questionnaire page. This is additional information on the page's procession – and extremely valuable when searching for problems with filters and/or PHP code (Solving Questionnaire Problems).
  3. SoScisurvey will show hints and alerts if it detects a problem. This information is not shown to normal respondents (in contrast to failures).

The debug information explain, among other things, the results of the value() function and when the questionaire jumps to which page using goToPage(). Using debug(), the debug mode also shows the contents of PHP variables. If these information are not as expected, you usually found the failure.

Filters in the Forum

Problem not solved? Then you can ask for advice in the SoSci Survey Online-Support. You should include the following information:

  1. On what question is the filter based on (question type and ID)?
    1. On which page is the filter question
    2. What are the variable(s) and answer codes of the filter question (Variable Listing)?
  2. On which page(s) is the question, stimulus, etc. that should be filtered?
  3. Which filter (PHP code) has been tried before, unsucessfully?
    1. On which page is the PHP code of the filter?
    2. What should happen under which conditions?
    3. What is shown by the debug information on the page of the filter?
en/create/filter-solving.txt · Last modified: 27.11.2020 21:08 by sophia.schauer
Except where otherwise noted, content on this wiki is licensed under the following license: CC Attribution-Share Alike 4.0 International
Driven by DokuWiki