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
Last revisionBoth sides next revision
en:create:transfer-responses [31.03.2016 16:24] hotaitdeen:create:transfer-responses [29.04.2021 20:43] sophia.schauer
Line 1: Line 1:
-Insert Answer Texts in Follow-up Questions +====== Show Answers in Follow-up Question ====== 
-Placeholders allow you to use participants‘ text inputs elsewhere in the questionnaire. This chapter provides you with a number of examples.+ 
 +[[:en:create:Placeholders|Placeholders]] allow you to use participants‘ text inputs elsewhere in the questionnaire. This chapter provides you with a number of examples (also known as "piping"). 
 + 
 +**Example:** At the beginning of the questionnaire, the participant selects which online network he personally uses most often. In later questions, the name of the network (e.g., "diaspora*") should then appear in question and item texts (e.g., "How often do you use diaspora* on a usual workday?")
    
-Note: If in a follow-up question you only want to display specific scale items or select options dependent on the participant’s response, please refer to Use Selected Items In Another Question.+**Note:** If in a follow-up question you only want to display specific scale items or select options dependent on the participant’s response, please refer to [[:en:create:filter-items]].
  
-Note: If you haven’t worked with filters and PHP code, please refer to chapters Introduction to PHP and Problem Solution for Filters first.+**Note:** If you haven’t worked with filters and PHP code, please refer to chapters [[:de:create:php]] and [[:de:create:filter-solving]] first.
  
  
-Use Single Answers +===== Use Open Text Answers =====
-On page 2 the participant mentioned the name of a TV presenter in a text input field (tagging TX01_01). Answer validation was applied to ensure the participant did enter something. The entered name is now to be included in following question texts or scale items. +
  
-In the first step, create a placeholder replace() for the name, e. g. %tvpresenter. In order to do so, place the following PHP code on page of the questionnaire following the text input question (eg. in the example on page 3 or later):+On page 2 the participant mentioned the name of a TV presenter in a text input field (tagging ''TX01_01'')Answer validation was applied to ensure the participant did enter somethingThe entered name is now to be included in following question texts or scale items. 
  
- +In the first step, create a placeholder ''[[:en:create:functions:replace]]'' for the name, e. g. ''%presenter%''. In order to do so, place the following PHP code on a page of the questionnaire following the text input question (e. g. in the example on page 3 or later):
  
 +<code php>
 +replace('%presenter%', 'TX01_01', 'response');
 +</code>
  
-This placeholder can then be inserted anywhere in the questionnaire – of course, only after it was created via PHP code. For example, the question text of a question on page 3 could be as follows:+This placeholder can then be inserted anywhere in the questionnaire -– of course, only after it was created via PHP code. For example, the question text of a question on page 3 could be as follows:
  
-Please assess <strong>%tvpresenter%</strong> with regard to the following characteristics.+<code> 
 +Please assess <strong>%presenter%</strong> with regard to the following characteristics. 
 +</code>
  
-Note: It is not possible to use replace() to display the participant’s entry immediately on the same page of the questionnaire. This function would require JavaScript.+**Note:** It is not possible to use ''replace()'' to display the participant’s entry immediately on the same page of the questionnaire. This function would require [[:en:create:javascript|JavaScript]].
  
-Note: In order to check if the placeholder functions correctly, you need to re-start the questionnaire from the beginning – or at least from the page with the text input field where the relevant name was entered (in the example on page 2).+**Note:** In order to check if the placeholder functions correctly, you need to re-start the questionnaire from the beginning – or at least from the page with the text input field where the relevant name was entered (in the example on page 2).
  
-Tip: Once a placeholder has been created, it remains valid for any following pages in the questionnaire. Repeating the PHP code on every page is not required. +**Tip:** Once a placeholder has been created, it remains valid for any following pages in the questionnaire. Repeating the PHP code on every page is __not__ required. 
  
-Tip: The above described PHP code also allows you to enter predefined answers (e.g. from a multi-choice question) in follow-up questions.+**Tip:** The above described PHP code also allows you to enter predefined answers (e.g. from a multi-choice question) in follow-up questions.
  
-Tip: As an alternative, the participant’s entry can be read out via value() and subsequently be transferred to replace().+**Tip:** As an alternative, the participant’s entry can be read out via ''[[:en:create:functions:value]]'' and subsequently be transferred to ''[[:en:create:functions:replace]]''.
  
- +<code php> 
 +$name = value('TX01_01'); 
 +replace('%presenter%', $name); 
 +</code>
  
 +===== Use Closed Answers =====
  
-Insert Several Answer Texts +The use of closed responses works in the same way as open responses.
-A question of the question type “Text Input” (“TX01”) or “Free Mention” (“TX02”) is presented to the participant. Up to 10 answers can be chosen. In a follow-up question (e. g. multiple selection, rank, scale) the answers are to be displayed as items or options+
  
-The problem in this example is that the participant might complete only part of the input fieldsConsequently, the follow-up questions must only display the relevant items/options. Also, it would mean a lot of extra work to write redirect() 10 times. A for-loop handles the iteration.+The following example assumes that in choice question ''SN01'' the participant selected the online network he or she uses most oftenThe following PHP code (placed on the following page or later) ensures that the placeholder ''%sns%'' is subsequently always replaced by the name of the selected network.
  
-In order for the follow-up question to function (e. g. “FQ01”) properlycreate that question as follows: The number of items/options in the question must equal the number of possible text inputs (in the example: 10), and texts used for the items/options are placeholders, e. g.  %text1% to %text10%.+<code php> 
 +replace('%sns%''SN01', 'response')
 +</code>
  
- +If one were to read the response to ''SN01'' using ''[[:en:create:functions:value]]'', one would first get the numeric response code. If you want to read the text of the response option for further processing, you can either use the command ''[[:en:create:functions:getitemtext]]'' -- or much simpler -- specify '''label''' as the second parameter in ''value()''.
  
-Tip: Of courseadditional text may be added to the placeholders, e. g“evaluation%text1%”.+<code php> 
 +$answer = value('SN01''label'); 
 +html('<h1>'.$answer.'</h1>'); 
 +</code>
  
-Via value() the following PHP code reads out all of  the ten possible text input fields, checks if an entry has been made, creates the placeholders %text1% to %text10%  and displays question FQ01 with the matching items/options.+Multiple choise questions are a spezial case. Here you can either look at the individual selection options (each is represented by its own variable, cf. **Variables overview**or the entire question.
  
-Important: The PHP codes for “Text Input“ and “Free Mention” differ slightly in line 4because the variables are determined according to different patterns (“TX01_01” vs“TX02x01”).+  * The command ''value('MA01')'' applied to the multiple selection ''MA01'' does not (!) return the code of the first selected optionbut the number of selected (non-exclusive) options. 
 +  * The command ''value('MA01', 'label')'' returns a comma-separated list of the selected options. The same applies to the use of ''replace('%placeholder%', 'MA01', 'response')''..
  
- +===== "Other" Input Fields ===== 
 + 
 +If one uses a choice question with an open residual category "Other: %%___%%", then ''replace('%sns%', 'SN01', 'response')'' continues to work. If the participant chooses one of the given selection options, the placeholder will be replaced by it. If he chooses a selection option with an open input field, the placeholder is replaced by the participant's text input. 
 + 
 +<code php> 
 +replace('%sns%', 'SN01', 'response'); 
 +</code> 
 + 
 +The function ''value()'' is a bit more strict. ''value('SN01', 'label')'' returns the text "Other:". If, on the other hand, you specify '''free''' as the third parameter (''value('SN01', 'free')''), you get either the selected option or -- if an option with an open input field was selected -- the participant's open input. 
 + 
 + 
 + 
 +===== Insert Several Answer Texts ===== 
 + 
 +A question of the question type "Text Input" (''TX01'') __or__ "Free Mention" (''TX02'') is presented to the participant. Up to 10 answers can be chosen. In a follow-up question (e. g. multiple selection, rank, scale) the answers are to be displayed as items or options.  
 + 
 +The problem in this example is that the participant might complete only part of the input fields. Consequently, the follow-up questions must only display the relevant items/options. Also, it would mean a lot of extra work to write ''redirect()'' 10 times. A for-loop handles the iteration. 
 + 
 +In order for the follow-up question to function (e. g. ''FQ01'') properly, create that question as follows: The number of items/options in the question must equal the number of possible text inputs (in the example: 10), and texts used for the items/options are placeholders, e. g. ''%text1%'' to ''%text10%''
 + 
 +<code> 
 +%text1% 
 +%text2% 
 +%text3% 
 +%text4% 
 +%text5% 
 +%text6% 
 +%text7% 
 +%text8% 
 +%text9% 
 +%text10% 
 +</code> 
 + 
 +**Tip:** Of course, additional text may be added to the placeholders, e. g. "evaluation %text1%"
 + 
 +Via ''[[:en:create:functions:value]]'' the following PHP code reads out all of  the ten possible text input fields, checks if an entry has been made, creates the placeholders ''%text1%'' to ''%text10%'' and displays question FQ01 with the matching items/options.
  
-Explanatory note on the PHP code: The IF filter at the end ensures that the follow-up question is skipped if the participant has not completed the relevant field. Through trim() blank spaces at the beginning and end of the text entered are removed so that a number of blanks entered into a text field are not interpreted as a valid answer.  Through sprintf() with its parameter %02d it is ensured that numbers are displayed as double-digits with leading zeros (e. g. 01 instead of 1).+<code php> 
 +$question = 'TX01'; 
 +$items = array(); 
 +for ($i=1; $i<=10; $i++) { 
 +  $itemID = id($question, $i); 
 +  $answer = value($itemID); 
 +  if (trim($answer!= '') { 
 +    replace('%text'.$i.'%', $answer); 
 +    $items[] = $i; 
 +  
 +
 +// show follow up question 
 +if (count($items> 0) { 
 +  question('FF01', $items)
 +
 +</code>
  
-Note: If the PHP code does not provide the required results, please refer to chapter Problem Solution for Filters.+Explanatory note on the PHP code: The IF filter at the end ensures that the follow-up question is skipped if the participant has not completed the relevant field. Through ''trim()'' blank spaces at the beginning and end of the text entered are removed so that a number of blanks entered into a text field are not interpreted as a valid answer.  Through ''sprintf()'' with its parameter '''%02d''' it is ensured that numbers are displayed as double-digits with leading zeros (e. g. ''01'' instead of ''1'').
  
 +**Note:** If the PHP code does not provide the required results, please refer to chapter [[:en:create:filter-solving]].
  
  
en/create/transfer-responses.txt · Last modified: 13.02.2024 19:03 by admin
 
Except where otherwise noted, content on this wiki is licensed under the following license: CC Attribution-Share Alike 4.0 International
Driven by DokuWiki