Create token on the fly

More
7 months 2 weeks ago #153264 by badronald
badronald created the topic: Create token on the fly
I need to create tokens on the fly.
I used to do this with newtoken.php but that does not seem to work with 2.06

I have participants register for survey 1 depending on how they answer they need to go on to survey1 or survey2 immediately with the same token.

How can I do this?
I have been searching the forums for hours.

Please Log in to join the conversation.

More
7 months 2 weeks ago - 7 months 2 weeks ago #153266 by tpartner
tpartner replied the topic: Create token on the fly

Cheers,
Tony Partner
Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
Last Edit: 7 months 2 weeks ago by tpartner.
The following user(s) said Thank You: badronald

Please Log in to join the conversation.

More
7 months 2 weeks ago #153269 by gabrieljenik
gabrieljenik replied the topic: Create token on the fly
Hi. I have a plugin which can help.
Please contact me at This email address is being protected from spambots. You need JavaScript enabled to view it.

Thanks

Cheers,
Gabriel - www.Encuesta.Biz - Authorized Partner

Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
Assistance on LimeSurvey forum and LimeSurvey core developpement are on my free time (Say thanks ?)....[img]

Please Log in to join the conversation.

More
7 months 2 weeks ago #153373 by badronald
badronald replied the topic: Create token on the fly
I cannot seem to figure out how to use the remote control feature . But I appreciate the feedback, thank you!

Please Log in to join the conversation.

More
7 months 2 weeks ago #153395 by tpartner
tpartner replied the topic: Create token on the fly
Did you try the linked example? If so, how did it fail?

Cheers,
Tony Partner
Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.

Please Log in to join the conversation.

More
7 months 2 weeks ago #153426 by badronald
badronald replied the topic: Create token on the fly
It is ok. It is just me. I do not have the time right now to figure out how to use the remote control system. I enabled it in limesuvey. But from there I am lost. I am not familiar with APIs.

Please Log in to join the conversation.

More
7 months 1 week ago - 7 months 1 week ago #153478 by badronald
badronald replied the topic: Create token on the fly
I just keep getting this error"


Warning: require_once(/application/libraries/jsonRPCClient.php) [function.require-once]: failed to open stream: No such file or directory in /home/nhs2/public_html/limesurvey206/admin/remotecontrol/newtoken.php on line 3

Fatal error: require_once() [function.require]: Failed opening required '/application/libraries/jsonRPCClient.php' (include_path='.:/usr/lib/php:/usr/local/lib/php') in /home/nhs2/public_html/limesurvey206/admin/remotecontrol/newtoken.php on line 3
Last Edit: 7 months 1 week ago by badronald.

Please Log in to join the conversation.

More
7 months 1 week ago #153494 by tpartner
tpartner replied the topic: Create token on the fly

Cheers,
Tony Partner
Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.

Please Log in to join the conversation.

More
7 months 1 week ago #153502 by badronald
badronald replied the topic: Create token on the fly
I finally got it!
thank you

Please Log in to join the conversation.

More
6 months 3 weeks ago #155043 by badronald
badronald replied the topic: Create token on the fly
Can I pass user token into url after registration? Using Remote Control 2?

Please Log in to join the conversation.

More
6 months 1 week ago #155468 by badronald
badronald replied the topic: Create token on the fly
I am trying to understand how this works....sorry for my confusion....I got the code working....after I have participants register, I would need to write code in AJAX to connect to the remotecontrol code page in order to have in run and insert the token into the token table?

Please Log in to join the conversation.

More
6 months 1 week ago - 6 months 1 week ago #155472 by tpartner
tpartner replied the topic: Create token on the fly
Yes, if you need to make an AJAX call from your website or application, it would look something like this:

<script type="text/javascript" charset="utf-8">
	$(document).ready(function() {
 
		// Identify some vars...
		var apiFilePath = 'http//path/to/api/file.php';
		var sid = 123456;
		var token = 'ABCDE';
		var email = 'example@example.com'; 
		var firstName = 'Fred'; 
		var lastName = 'Flinstone'; 
 
		// AJAX call
		$.ajax({  
			url: apiFilePath, // Path to the PHP file
			async: true,
			cache : false, // No caching in IE
			data: {
				sid: sid, 
				token: token,
				email : email, 
				firstName: firstName, 
				lastName: lastName 
			},
			success: function(results){	
				// Do something with the returned results of the AJAX call
			},
			error: function(){
				alert('Could not connect!');
			}
		}); 
	});
</script>

Then you would need to redefine the variables in the PHP file to access the GET values something like this:

$iSurveyID = $_GET["sid"];
$token = $_GET["token"];
$email = $_GET["email"];
$LastNameAPI = $_GET["firstName"];
$FirstNameAPI = $_GET["lastName"];

More info on jQuery AJAX here - api.jquery.com/jquery.ajax/

Cheers,
Tony Partner
Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
Last Edit: 6 months 1 week ago by tpartner.

Please Log in to join the conversation.

More
6 months 1 week ago #155474 by badronald
badronald replied the topic: Create token on the fly
Thank you!

Please Log in to join the conversation.

More
6 months 5 days ago - 6 months 5 days ago #155568 by badronald
badronald replied the topic: Create token on the fly
I currently am using ls 2.06
I need to add tokens as people do the survey, I used to do this via the newtoken.php workaround
I have 2 surveys.....that need to to be connected via a token
I am trying to figure out the remote control feature but I am totally lost.

I have setup survey one to require registration, which creates a token, I would like then to pass this token to survey2 .

Is this possible? usnig end url something like ....

<?php
require_once 'jsonRPCClient.php';
define( 'LS_BASEURL', '/index.php/');
define( 'LS_USER', '****' );
define( 'LS_PASSWORD', '****' );

$iSurveyID = 375394;
$token = 'ABCDE';


// Instantiate a new RPC client
$myJSONRPCClient = new jsonRPCClient(LS_BASEURL.'admin/remotecontrol');

// Get a session key
$sSessionKey= $myJSONRPCClient->get_session_key( LS_USER, LS_PASSWORD );

// Define the token params
$tokenParams = array("token"=>$token,"language"=>'fr',"emailstatus"=>"OK");
$aParticipantData=array($tokenParams);
$bCreateToken = true;

// Create the tokens
$newToken = $myJSONRPCClient->add_participants( $sSessionKey, $iSurveyID, $aParticipantData, $bCreateToken);

// Print returned results
echo '<hr><br><h1>Limesurvey</h1><br>New token created in survey '.$iSurveyID.':'
.'<ul>'
.'<li>TID - '.$newToken[0].'</li>'
.'<li>Token - '.$newToken[0].'</li>'
.'</ul>';

// Send an invitation to the created token
$tokenIDs = array($newToken[0]);
$newMail = $myJSONRPCClient->invite_participants($sSessionKey, $iSurveyID, $tokenIDs, true);

// Print returned results
if($newMail[$newToken[0]] == 'OK') {
echo 'Invitation sent to:'
.'<ul>'
.'<li>Name - '.$newMail[$newToken[0]].'</li>'
.'<li>Email - '.$newMail[$newToken[0]].'</li>'
.'</ul>';
}
else {
echo 'Error - no invitation sent!';
}

// Release the session key
$myJSONRPCClient->release_session_key( $sSessionKey );
?>
Last Edit: 6 months 5 days ago by badronald.

Please Log in to join the conversation.

More
3 months 1 week ago #158141 by badronald
badronald replied the topic: Create token on the fly
I am still horribly lost with creating tokens.

I need to register people, then have them complete a survey.
I need it all connected via a token. Ideally, to insert same token into registration table and survey.

I can make a registration form. I can get the remotecontrol API add participants to show and insert a token.
I am having trouble connecting these 2 pieces.... that is....register someone, use the API, and redirect to new survey.

Please Log in to join the conversation.

Start now!

Just create your account and start using Limesurvey today.

Register now
Join our Newsletter!