[[replace()]]
 

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:replace [15.01.2015 20:05] – [replace()] alexander.ritteren:create:functions:replace [20.08.2018 08:05] (current) admin
Line 10: Line 10:
     * '''text''' -- (default) The //content// is read as plain text.     * '''text''' -- (default) The //content// is read as plain text.
     * '''html''' -- The //content// is read as HTML code. HTML special characters (such as ''<'' or ''>'') are tranferred unmasked into the questionnaire's source code.      * '''html''' -- The //content// is read as HTML code. HTML special characters (such as ''<'' or ''>'') are tranferred unmasked into the questionnaire's source code. 
-    * '''response'''  A variable ID is specified as the //content//. The placeholder should be replaced with the response of the participant to this variable. The way the response is determined is equivalent to ''[[:en:create:functions:value|value(..., 'text')]]''. **Note:** The participant must first transmit the response to the server with "Next" before it can be called up with PHP code. Therefore, ''[[:en:create:functions:replace(..., 'response')]]'' must not be used on the same page as the question; on the following page at the earliest.  +    * '''response'''  A variable ID is specified as the //content//. The placeholder should be replaced with the response of the participant to this variable. The way the response is determined is equivalent to ''[[:en:create:functions:value|value(..., 'text')]]''. **Note:** The participant must first transmit the response to the server with "Next" before it can be called up with PHP code. Therefore, ''replace(..., 'response')'' must not be used on the same page as the question; on the following page at the earliest.  
-   +    * '''special''' -- Use one of the following IDs as //content// to employ dynamic data for the placeholder: 
 +      * '''qn-''' -- The last number used for a question (e.g., to refer to the previous question in instructions). 
 +      * '''qn+''' -- Create a new question number (e.g., to add a number to [[:en:create:inputs-custom|custom form inputs]]). 
 + 
 + 
 +====== Notes ====== 
 + 
 +**Important:** ''replace()'' must be placed before or above the element containing the placeholder. If the placeholder ''%test%'' is used e.g. in the text module "instruction", then the command ''replace('%test%', ...)'' must be invoked in the questionnaire before/above the text element. ''replace()'' can either be on the same page above the text module or on a previous page in the questionnaire. 
 + 
 +**Note:** To allow the ''replace()'' function to access a response from the participant (third parameter '''response'''), the participant must click "Next", __before__ ''replace()'' is invoked. As with the function ''[[:en:create:functions:value]]'', ''replace(..., 'AB01', 'response')'' must not be on the same page as question AB01. 
  
 ===== Examples ===== ===== Examples =====
Line 27: Line 37:
 // Replace %response% with the response of the participant to the single selection question AB02  // Replace %response% with the response of the participant to the single selection question AB02 
 replace('%response%', 'AB02', 'response'); replace('%response%', 'AB02', 'response');
 +
 +// Replace %number% by a new question number
 +replace('%number%', 'qn+', 'special');
 +html('<div class="title">%number%. Please select the ...</div>');
 </code> </code>
en/create/functions/replace.txt · Last modified: 20.08.2018 08:05 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