Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
en:create:functions:markfail [24.12.2014 17:57] – [markFail()] alexander.ritteren:create:functions:markfail [28.06.2021 18:05] (current) sophia.schauer
Line 3: Line 3:
 ''void **markFail**(string //variableID//)'' ''void **markFail**(string //variableID//)''
  
-The function ''markFail()'' is used in conjunction with a individual response check ([[:en:create:checks#individuelle_antwort-pruefung|Check Responses: Individual Response Check]]) and the function ''[[:en:create:functions:repeatpage|repeatPage()]]''. This means an input field is highlighted in such a way so that the participant can recognize where information is not correct. +The function ''markFail()'' is used in conjunction with a individual response check ([[:en:create:checks#customized__response_check|Check Responses: Customized Response Check]]) and the function ''[[:en:create:functions:repeatpage|repeatPage()]]''. This means an input field is highlighted in such a way so that the participant can recognize where information is not correct. 
  
  
Line 10: Line 10:
 There are two effects to using ''markFail()'': first of all, the input field will be highlighted visually, and secondly, the response is counted as a missing answer when calculating the variables ''MISSING'' and ''MISSREL'' ([[:en:results:variables|Additional Variables in the Data Record]]). The latter is particularly important if ''markFail()'' is used without ''repeatPage()'' There are two effects to using ''markFail()'': first of all, the input field will be highlighted visually, and secondly, the response is counted as a missing answer when calculating the variables ''MISSING'' and ''MISSREL'' ([[:en:results:variables|Additional Variables in the Data Record]]). The latter is particularly important if ''markFail()'' is used without ''repeatPage()''
  
-===== 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 "AB01_01" and "AB01_02". In addition, there is a multiple-choice selection option "I don't watch any television" with the ID "AB02_01". 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 "AB01_01" and "AB01_02". In addition, there is a multiple-choice selection option "I don't watch any television" with the ID "AB02_01".
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 "AC01"), the number of minutes in the second column ("AC02"), and a multiple-choice selection "AC03") serves as the third column.  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 "AC01"), the number of minutes in the second column ("AC02"), and a multiple-choice selection "AC03") serves as the third column. 
Line 39: Line 39:
 $items = getItems('AC01', 'all'); $items = getItems('AC01', 'all');
 foreach ($items as $item) { foreach ($items as $item) {
-  $idH = 'AC01_'.sprintf('%02d', $item); +  $idH = id('AC01', $item); 
-  $idM = 'AC02_'.sprintf('%02d', $item); +  $idM = id('AC02', $item); 
-  $idX = 'AC03_'.sprintf('%02d', $item);+  $idX = id('AC03', $item);
   if ((trim(value($idH)) == '') and (trim(value($idM)) == '') and (value($idX) != 2)) {   if ((trim(value($idH)) == '') and (trim(value($idM)) == '') and (value($idX) != 2)) {
     markFail($idH);     markFail($idH);
Line 52: Line 52:
 } }
 </code> </code>
 +
 +===== 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 = [
 +  'AW01' => 'Text1',
 +  'AW02' => 'Text2',
 +  'AW03_01' => 'Text3',
 +  'AW03_02' => 'Text3',
 +  'AW03_03' => 'Text3',
 +  'AW03_04' => 'Text4',
 +  // u.s.w.
 +];
 +
 +// Check all variables, mark and collect error codes
 +$messages = [];
 +foreach ($checks as $variable => $text) {
 +  $antwort = value($variable);
 +  if ((trim($answer)=== '') || ($answer < 1)) {
 +    markFail($variable);
 +    $messages[] = $text;
 +  }
 +}
 +
 +// If necessary, display error messages and repeat page
 +if (!empty($messages)) {
 +  $messages = array_unique($messages);
 +  html('<div class="feedback" role="status">');  // Red frame
 +  foreach ($messages as $text) {
 +    text($text, 'spacing=10');
 +  }
 +  html('</div>');
 +  repeatPage();
 +}
 +</code>
 +
 +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 ''%%(trim($response) === '')%%'' is only necessary if you also want to check text input. Otherwise ''%%($response < 1)%%'' checks for an error code. Unanswered input fields are directly marked with ''markFail()'' and the text identifier associated with the error message is noted in the array ''$messages''.
 +
 +The third part then checks if there are messages in the array ''$messages'', duplicates are removed with ''array_unique()''. The ''<div>'' in the HTML code provides the formatting as a feedback message (e.g. marked by a red frame) and within this the error messages are then output. Finally, the ''repeatPage()'' takes care of redisplaying the page.
en/create/functions/markfail.txt · Last modified: 28.06.2021 18:05 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