====== Filter by Text Input ======

Whether a specific value was selected in a selection or a scale is normally checked. In principle, the process is exactly the same if you want to check to see if a participant wrote something specific in a text input field.  

The difference here being that text is compared, rather than figures. 

===== Check If Something was Entered =====

Usually, the user just wants to check to see if something was written in a text input field. Or, worded differently for programmers: whether something other than the empty string (no text) was entered. The empty string is written using two single quotation marks (%%''%%) or two double quotation marks (%%""%%) with nothing in between. 

<code php>
if (value('AB01_01') != '') {
  question('BB01');
}
</code>

The above PHP code works but reacts sensitively to blank spaces: If a participant only enters blank spaces in a text field then this would actually be classified as "not specified". There is the function ''trim()'' for this, which removes blanks spaces at the beginning and end. The blank spaces are removed in the filter and then it carries out the comparison:

<code php>
if (trim(value('AB01_01')) != '') {
  question('BB01');
}
</code>


===== Check Minimum Length of Text =====

''strlen()'' is another useful function. It returns the number of characters (length) in a string (text). If we know that any meaningful data must be made up of at least 4 characters then the length of the string can also be checked. ''trim()'' is used here again so that any blank spaces do not cause any wrong decision-making. 

<code php>
if (strlen(trim(value('AB01_01'))) > 3) {
  question('BB01');
}
</code>

Or more legibly (in case the overview is lost with so many brackets):

<code php>
$input = value('AB01_01');  // participant's input
$withoutspaces = trim($input);   // remove blank spaces at beginning and end
$length = strlen($withoutspaces);  // determine length
if ($length > 3) {
  question('BB01');
}
</code>


===== Compare Text =====

If whether the participant gave the correct answer should be checked, this works by using the comparison operators ''=='' (equal) and ''!='' (not equal) -- as with numbers. The following filter should check whether the participant watched a test video. The text video shows a word which should be entered in the input field. If the participant enters the wrong word, the page with the test video is displayed again. 


<code php>
if (value('AB01_01') != 'cat') {
  repeatPage();
}
</code>

If there should not be any fussiness between upper and lower case, writing ''strtolower()'' in lower case before comparison converts the participant's input.

<code php>
if (strtolower(value('AB01_01')) != 'cat') {
  repeatPage();
}
</code>

Blank spaces at the beginning/end can be removed once again by using the familiar ''trim()'':

<code php>
if (strtolower(trim(value('AB01_01'))) != 'cat') {
  repeatPage();
}
</code>


===== Numbers in the Input =====

PHP is not fussy when it comes to differentiating between text and numbers. If you want to check if the participant gave a number greater than 10 in the input field ''AB01_01'', this can be done as follows:

<code php>
if (value('AB01_01') > 10) {
  question('BC02');
}
</code>

The input field should, however, then only be set to allow the participant to enter digits (see [[:en:create:checks#entering_numbers|Check Responses: Entering Numbers]]). If this cannot be set or is not desired, ''is_numeric()'' can be used to find out if the particpant entered a number. 

The following filter is only effective if the participant gave a number and this number is greater than 10. 

<code php>
$input = value('AB01_01');
if (is_numeric($input) and ($input > 10)) {
  question('BC02');
}
</code>

Likewise, PHP can be instructed to convert the participant's input into a number as best as possible. Therefore, "5b" becomes ''5''. The conversion takes place with the function ''intval()'' or with the prefix ''(int)'' (type casting). 

<code php>
$input = intval(value('AB01_01'));
if ($input > 10) {
  question('BC02');
}
</code>

<code php>
$input = (int)value('AB01_01');
if ($input > 10) {
  question('BC02');
}
</code>

**Take care:** Decimal places are cut off when using this solution. If you want to work with decimals, you have to first of all make sure that a period is used as the decimal separator (if necessary, set a text input that only allows decimals in SoSci Survey) and then carry out the conversion into a number using the prefix ''(float)''. 
