This shows you the differences between two versions of the page.
Next revision | |||
— | en:create:checks-php [22.07.2019 16:36] – created johannes.jungilligens | ||
---|---|---|---|
Line 1: | Line 1: | ||
+ | ====== Individual Response Check ======== | ||
+ | |||
+ | Formal requirements for an answer -- for example, that all items of a scale have been answered or that an open text input follows a certain pattern -- can be defined with a few clicks in the question ([[: | ||
+ | |||
+ | More complex checks can be done with a little [[: | ||
+ | |||
+ | **Important: | ||
+ | |||
+ | **Note:** Consider in advance whether checking the answer is really useful. This is the case if participants unintentionally enter their information in the wrong format. If, on the other hand, you expect participants to fail to adhere to the guidelines due to lack of motivation ("just click through" | ||
+ | |||
+ | **Tip:** For more details on programming PHP filters, see [[: | ||
+ | |||
+ | **Tip:** Use the '' | ||
+ | |||
+ | You can display an error message if you enter the ID of a text module as an argument in the '' | ||
+ | |||
+ | |||
+ | ===== Example: Multiple Selection Matrix ======= | ||
+ | |||
+ | In an ordinary scale you can easily check whether the participant has selected an option in each line. But if you use a [[: | ||
+ | |||
+ | The following example assumes that 4 multi-select questions (" | ||
+ | |||
+ | |||
+ | ==== Variant A ===== | ||
+ | |||
+ | One possibility is to simply count the selected items for each line (item). If nothing was selected, the item number is put on a list '' | ||
+ | |||
+ | The function [[: | ||
+ | |||
+ | <code php> | ||
+ | // The unanswered items are collected in the $missing list. | ||
+ | $missing = array(); | ||
+ | // The getItems() function returns a list of item numbers (=lines). | ||
+ | // The construction FOREACH goes through all of them in a loop | ||
+ | foreach (getItems(' | ||
+ | // Go through all columns (questions) for this item in a FOR loop | ||
+ | $anyChecked = false; | ||
+ | for ($col = 1; $col <= 4; $col++) { | ||
+ | $itemID = id(' | ||
+ | if (value($itemID) == 2) { | ||
+ | $anyChecked = true; | ||
+ | } | ||
+ | } | ||
+ | // Note item, if nothing was marked | ||
+ | if (!$anyChecked) { | ||
+ | $missing[] = $item; | ||
+ | } | ||
+ | } | ||
+ | |||
+ | // Check whether an item remained unanswered | ||
+ | if (count($missing) > 0) { | ||
+ | // Highlight the missing items | ||
+ | foreach ($missing as $item) { | ||
+ | markFail(id(' | ||
+ | } | ||
+ | // Display message and repeat page | ||
+ | repeatPage(' | ||
+ | } | ||
+ | </ | ||
+ | |||
+ | |||
+ | ==== Variant B ===== | ||
+ | |||
+ | If you prefer to work with sets of numbers, you can determine the unchecked items (code: 1) per column and form their overlap. | ||
+ | |||
+ | <code php> | ||
+ | $missing01 = getItems(' | ||
+ | $missing02 = getItems(' | ||
+ | $missing03 = getItems(' | ||
+ | $missing04 = getItems(' | ||
+ | $missing = array_intersect($missing01, | ||
+ | |||
+ | // Check whether an item remained unanswered | ||
+ | if (count($missing) > 0) { | ||
+ | // Highlight the missing items | ||
+ | foreach ($missing as $item) { | ||
+ | markFail(id(' | ||
+ | } | ||
+ | // Display message and repeat page | ||
+ | repeatPage(' | ||
+ | } | ||
+ | </ | ||
+ | |||
+ | |||
+ | ===== Example: All Items or None at All ====== | ||
+ | |||
+ | The following PHP code checks whether all items on a scale were answered -- or none at all. The question identifier (in this example '' | ||
+ | |||
+ | <code php> | ||
+ | // Create a list of all items in the question | ||
+ | $items = getItems(' | ||
+ | // Determining the answered items | ||
+ | $answered = getItems(' | ||
+ | // error and back, if not all or none were answered | ||
+ | if ((count($answered) > 0) and (count($answered) < count($items))) { | ||
+ | repeatPage(' | ||
+ | } | ||
+ | </ | ||