====== 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: [[:en:create:filters|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: - 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. - 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: [[:en:create:dynamic|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 ([[:en:create:questionnaire#delete_or_move_questions|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 ({{:button.debug.here.gif?nolink|Start the questionaire in the debug mode}}). The debug mode has three different aspects compared to the normal questionaire mode: - The identification of each question is shown in squared brackets. - 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 ([[:en:create:debugging]]). - 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 ''[[:de:create:functions:debug|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 [[https://support.soscisurvey.de|Online-Support]]. You should include the following information: - On what question is the filter based on (question type and ID)? - On which page is the filter question - What are the variable(s) and answer codes of the filter question (**Variable Listing**)? - On which page(s) is the question, stimulus, etc. that should be filtered? - Which filter (PHP code) has been tried before, unsucessfully? - On which page is the PHP code of the filter? - What should happen under which conditions? - What is shown by the debug information on the page of the filter?