====== Resuming by Means of an External Code ======
This manual describes how you can use a reference ([[:en:survey:url#marking_a_url_r|Marking a URL]]) or a person code passed otherwise ([[:en:create:questions:client]]), ...
* to resume an interrupted interview (see also [[:en:survey:resume]]).
* to prevent multiple participation (see also [[:en:survey:unique-respondents]]).
* to be able to resume multiple questionnaires in a survey project independently of each other (use different prefixes in the database keys for this).
**Note:** Only use this implementation if the regular solution by means of [[:en:survey:mailing:sosci|mailings]] or [[:en:survey:serials]] cannot be used for organizational reasons.
===== How It Works =====
This solution makes use of the [[:en:create:databank]]. For each person code, the [[:en:survey:url#interview_token_i|interview token]] (case token) is stored there. By means of the interview token, the previously started interview can be resumed.
===== Implementation =====
On the first page of the questionnaire, read the person ID. In this example, it would be passed as a reference (''r=...'') in the link.
$personID = reference();
Then check whether there is an entry for this person ID in the content database. The following PHP code additionally prepends a prefix ''user'' to the ID. This makes it easier to use the database for different purposes. The prefix can be chosen freely.
$key = 'user-'.$personID;
$info = dbGet($key);
If an entry exists, the respondent is directly redirected to the corresponding case, and the current interview is deleted from the dataset. Otherwise (''else''), the interview token of the current interview is written to the database.
if ($info) {
$url = info('project.url').'?i='.$info[0];
dropCase();
redirect($url);
} else {
dbSet($key, caseToken());
}
The PHP code parts mentioned above must all be placed together in one "PHP code" element. This element must be placed at the very top of the first questionnaire page. However, it is also conceivable, for example, to write the entry to the content database only after a screenout. In that case, the ''else'' part at the beginning would be omitted, and the code placed later would look as follows.
$personID = reference();
$key = 'user-'.$personID;
dbSet($key, caseToken());
Thus, an interview would only be resumed if the place with the second PHP code containing ''dbSet()'' was reached.