This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
en:create:functions:markfail [24.12.2014 17:57] – [Example 2] alexander.ritter | en:create:functions:markfail [28.06.2021 18:05] (current) – sophia.schauer | ||
---|---|---|---|
Line 3: | Line 3: | ||
'' | '' | ||
- | The function '' | + | The function '' |
* // | * // | ||
- | There are two effects to using '' | + | There are two effects to using '' |
- | ===== Example 1 ===== | + | ===== At Least One Case Filled |
In the following example, the participant is asked how many hours and minutes a person watches television every day on page 1 of the questionnaire. The answers are to be written in the free text input fields " | In the following example, the participant is asked how many hours and minutes a person watches television every day on page 1 of the questionnaire. The answers are to be written in the free text input fields " | ||
Line 29: | Line 29: | ||
- | ===== Example 2 ===== | + | ===== Check Multiple Items ===== |
Here, the participant is asked the hours and minutes and a residual option -- just like in example 1. This time, however, in a combined question with 10 different forms of media. The number of hours are asked in the first column (question " | Here, the participant is asked the hours and minutes and a residual option -- just like in example 1. This time, however, in a combined question with 10 different forms of media. The number of hours are asked in the first column (question " | ||
Line 39: | Line 39: | ||
$items = getItems(' | $items = getItems(' | ||
foreach ($items as $item) { | foreach ($items as $item) { | ||
- | $idH = ' | + | $idH = id('AC01', $item); |
- | $idM = ' | + | $idM = id('AC02', $item); |
- | $idX = ' | + | $idX = id('AC03', $item); |
if ((trim(value($idH)) == '' | if ((trim(value($idH)) == '' | ||
markFail($idH); | markFail($idH); | ||
Line 52: | Line 52: | ||
} | } | ||
</ | </ | ||
+ | |||
+ | ===== Different Feedback Texts ===== | ||
+ | |||
+ | Sometimes the error messages should be adjusted more precisely to the missing variables. The following PHP code demonstrates how to select the appropriate texts and avoid the duplicate display. | ||
+ | |||
+ | <code php> | ||
+ | // Variables and related error codes | ||
+ | $checks = [ | ||
+ | ' | ||
+ | ' | ||
+ | ' | ||
+ | ' | ||
+ | ' | ||
+ | ' | ||
+ | // u.s.w. | ||
+ | ]; | ||
+ | |||
+ | // Check all variables, mark and collect error codes | ||
+ | $messages = []; | ||
+ | foreach ($checks as $variable => $text) { | ||
+ | $antwort = value($variable); | ||
+ | if ((trim($answer)=== '' | ||
+ | markFail($variable); | ||
+ | $messages[] = $text; | ||
+ | } | ||
+ | } | ||
+ | |||
+ | // If necessary, display error messages and repeat page | ||
+ | if (!empty($messages)) { | ||
+ | $messages = array_unique($messages); | ||
+ | html('< | ||
+ | foreach ($messages as $text) { | ||
+ | text($text, ' | ||
+ | } | ||
+ | html('</ | ||
+ | repeatPage(); | ||
+ | } | ||
+ | </ | ||
+ | |||
+ | The PHP code consits of three parts. In the first part, the variables to be checked are defined in an array and which error message should be displayed in each case if the variable is not answered. | ||
+ | |||
+ | In the second part, all variables are then checked individually in a FOR loop. The '' | ||
+ | |||
+ | The third part then checks if there are messages in the array '' |