[[readGET()]]
Translations of this page:
 

Table of Contents

readGET()

string|false readGET(string ID, [boolean warning])

The function readGET() allows a variable to be read that was transmitted to the questionnaire via POST or GET.

  • ID
    name of the variable transmitted
  • warning
    should a warning be displayed if the command is used on a different page other than the first?
    • true – (standard) display warning (warning is only visible to the project administrator, not the participant)
    • false – hide warning: the project administrator knows what he is doing

The function's return value is the string that was transmitted using POST or GET when the questionnaire is called up. If the variable was not transmitted, false will be returned.

Notes

  • Reading only works on the first page of the questionnaire, or on a page that was prepared for a break using option('resume', true), or if the project administrator ensures the variable was transmitted by using an appropriate link.
  • Certain variables have a specific meaning and should not be used to transfer user-defined data; see URL to the Questionnaire.
  • Before using readGET(), check whether a value has already been set. In the examples below, isset() or getRoute() is used to do so. For example, if you put a compulsory question on the first page in the questionnaire, the first page will be shown again if no answer is given, but readGET() is unable to read the value anymore. This “no value” would then overwrite the correct value already stored.

Example 1

For example, the variable panelID was transmitted with the value “12345” (e.g. https://www.soscisurvey.de/demo/?panelID=12345) and so the value “12345” can be determined with readGET('panelID').

The use of isset() ensures that the value read will not be overwritten if the page is shown again later (.e.g. after pressing the back button or if the page is repeated again as answers are missing).

if (!isset($id)) {
  $id = readGET('panelID');
  // register variable for later use
  registerVariable($id);
}

Example 2

In the following code example, two variables (tic and pid) are read on the first page of the questionnaire and saved as internal variables. The internal variables IV01_01 and IV01_02 have to be created beforehand in the List of Questions.

In addition, the ID for pid is set up as the placeholder %pid% in order for it to be used later in a redirect link (e.g. https://www.panelanbieter.com/redirect.php?user=%pid%).

Here, the use of getRoute() ensures that reading and, crucially, put is implemented at the start of the questionnaire only.

if (getRoute() == 'start') {
  $tic = readGET('tic');
  put('IV01_01', $tic);
  $pid = readGET('pid');
  put('IV01_02', $pid);
  // set up pid in addition as placeholder to redirect
  replace('%pid%', $pid);
}
en/create/functions/readget.txt · Last modified: 29.09.2020 16:53 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