An alternative may be to redirect to an intermediate PHP page before redirecting to Sawtooth. This PHP page could use the API to increment (or change) the "lastpage" value of the response so when the respondent returns to the survey after Sawtooth (via token response persistence) they land at a new "lastpage".
A note: To update the response via the
update_response() method, you will also need to enable "Allow multiple responses or update responses with one token" -
www.limesurvey.org/manual/Participant_se...onses_with_one_token
.
Here is a small PHP example which:
- Uses the
export_responses_by_token() method to determine the response ID and lastpage values.
- Increments the lastpage value.
- Uses the
update_response() method to modify the lastpage value.
- Redirects to another webpage.
Code:
<?php
require_once 'jsonRPCClient.php';
define( 'LS_BASEURL', 'https://localhost/limeSurvey3x');
define( 'LS_USER', 'admin' );
define( 'LS_PASSWORD', 'password' );
$iSurveyID = $_GET['sid'];
$sToken = $_GET['token'];
if(ctype_alnum($iSurveyID) && (strlen($iSurveyID) == 5 || strlen($iSurveyID) == 6)) { // Valid SID format
// Instantiate a new RPC client
$myJSONRPCClient = new jsonRPCClient( LS_BASEURL.'/index.php/admin/remotecontrol' );
// Get a session key
$sSessionKey= $myJSONRPCClient->get_session_key( LS_USER, LS_PASSWORD );
if(is_array($sSessionKey)) { // Invalid session
echo $sSessionKey['status'];
}
else if($sSessionKey) { // Valid session
// Get a response by token to determine the response ID and lastpage values
$aFields = array('id', 'lastpage');
$tokenResponse = $myJSONRPCClient->export_responses_by_token($sSessionKey, $iSurveyID, 'json', $sToken, null, 'all', 'code', 'short', $aFields);
if(is_array($tokenResponse)) {
// Oops, a response error...
// Print any errors
print_r($tokenResponse);
// Release the session key
$myJSONRPCClient->release_session_key( $sSessionKey );
}
//
else {
// There is a valid response...
// Decode the returned base-64 string and convert to an array
$decodedString = base64_decode($tokenResponse);
$tokenResponseArr = json_decode($decodedString, True);
// Get the first item in the $tokenResponseArr['responses'][0] array
$tokenResponseArr2 = reset($tokenResponseArr['responses'][0]);
// Define vars for the response ID and lastpage values
$responseID = $tokenResponseArr2['id'];
$responseLastpage = $tokenResponseArr2['lastpage'];
// Increment the lastpage
// ...or, you could hard-code a lastpage value here instead
$responseLastpage++;
// Update the response lastpage value
$aResponseData = array(
'id' => $responseID,
'lastpage' => $responseLastpage
);
$updatedResponse = $myJSONRPCClient->update_response($sSessionKey, $iSurveyID, $aResponseData);
// Release the session key
$myJSONRPCClient->release_session_key( $sSessionKey );
// Redirect to the next site
header("Location: https://google.com");
die();
}
}
}
else { // Invalid SID format
die( 'Invalid format!' );
}
?>