Check out the LimeSurvey source code on GitHub!

Is it possible to pass the token in the url and store as a hidden field?

More
5 years 5 months ago #64119 by dataguru
I installed Limesurvey Friday and have customized a template and built my first survey. You guys have done a really great job building it!!

Before I activate the survey for testing:

Is it possible to pass the token in the url and store as a hidden field rather than asking the user to enter it?

The token value is stored with the survey data when that's written? (I'll need to use it to link back to some other data used for reporting.)

Also, I'd like to embed the opt out code in the survey template, so the user can opt out at any time. Does the opt out code automatically include the token? or is there a better way to do that?

Thanks!
Betty

Please Log in to join the conversation.

More
5 years 5 months ago #64142 by tpartner
1) Yes, when you send the token to the respondent (using the built-in mail feature) the URL will look something like:
http://yourSurveySite.com/limesurvey/index.php?lang=en&sid=12345&token=678

2) If the survey is non-anonymous the token (and custom attributes) will be stored in the data and can be exported with all other results.

3) I think you would need to use the {url} and {TOKEN} keywords to create the string in your template. See docs.limesurvey.org/The+template+editor&...+LimeSurvey#Keywords and docs.limesurvey.org/The+template+editor&...+LimeSurvey#Keywords .

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
5 years 5 months ago - 5 years 5 months ago #64156 by dataguru
Thanks Tony!!

so something like:
To opt out of the survey <a href="{url}?token={TOKEN}">click here</a>.
or
To opt out of the survey <a href="{OPTOUTURL}">click here</a>.

I added 2nd version using {OPTOUTURL} right before the first end div in theendpage.pstpl

and when I preview the survey, the link is:
eteam.ou.edu/survey/{OPTOUTURL }
Last Edit: 5 years 5 months ago by dataguru.

Please Log in to join the conversation.

More
5 years 5 months ago #64181 by tpartner
I haven't tested but maybe something like:
<a href="http://yourSurveySite/limesurvey//optout.php?lang=en&sid=12345&token={TOKEN}">Opt out</a>

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
5 years 5 months ago #64205 by dataguru
I know now why {OPTOUTURL} didn't work. It's not available in the endpage.pstpl. {TOKEN} isn't available there either.

I also tried using php in the template
<p><a href="http://eteam.ou.edu/survey//optout.php?lang=en&sid=<?php echo $scid; ?>&token=<?php echo $clienttoken; ?>">Click here to opt out of this survey</a></p>

and
<p><a href="http://eteam.ou.edu/survey//optout.php?lang=en&sid=<?php echo $_GET["sid"]; ?>&token=<?php echo $_GET["token"]; ?>">Click here to opt out of this survey</a></p>

but it keeps removing the <?

Please Log in to join the conversation.

More
5 years 5 months ago #64206 by dataguru
hmmmm perhaps using javascript.
docs.limesurvey.org/Workarounds%3A+Manip...vious_To_Top_Of_Page

I'd think it would be possible to add some javascript to display the optout option.

Please Log in to join the conversation.

More
5 years 5 months ago #64207 by dataguru
I think I suck at this.

I tried adding this at the end of the template.js file. Nothing appeared to happen when I previewed the survey.
$(document).ready(function() {
 
		// Insert a new div after the progress bar
		$('<div id="navigator2" />').insertAfter('#progress-wrapper');
 
		// Style the new div
		$('#navigator2').css({
			'text-align':'center'
		});
 
		// Insert opt out url in the new div
		document.write("<p>here it is</p>");
 
	});
I suppose it might help if I was more familiar with javascript.

Please Log in to join the conversation.

More
5 years 5 months ago #64233 by tpartner

It's not available in the endpage.pstpl.

I'm not sure why you would want an opt-out link on the end page, the respondents will already have completed the survey.

You can't use keywords in template.js. They are replaced before the page loads by the core PHP.

I think you may need to set up your survey to use JavaScript and add something like this to the source of every group description (if using group-by-group) or every question (if using question by question).
<script type="text/javascript" charset="utf-8">
 
	$(document).ready(function() {
 
		// Find the survey ID
		if($('input#fieldnames').length != 0) {
			var fieldNames = $('input#fieldnames').attr('value');
			var tmp = fieldNames.split('X');
			var sID = tmp[0];
		}
 
		// Insert a new div after the progress bar
		$('<div id="optOutLink" />').insertAfter('#progress-wrapper');
 
		// Style the new div
		$('#optOutLink').css({
			'text-align':'center'
		});
 
		// Insert opt out url in the new div
		$('#optOutLink').html('<a href="optout.php?lang=en&sid='+sID+'&token={TOKEN}">Click here to opt out</a>');
 
	});
 
</script>

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
5 years 5 months ago #64244 by dataguru
Sorry for being such a newby, :)

to me endpage.pstpl looked like it displays the bottom of each page, not the last page.

I just want to it display on the each survey page so the user is able to opt out at any time.

That really helps. So it didn't display last time because I didn't enable javascript. duh.

Thanks so much for your help.

The reason I'm doing this is because our IRB wants them to be able to opt out at any time. It just occurred to me that I could add verbage to the e-mail telling then they can click on that opt out link in the e-mail at any time during the survey to opt out. That might satisfy out IRB. The opt out link in the e-mail would work after someone had started their survey?

Betty

Please Log in to join the conversation.

More
5 years 5 months ago #64254 by dataguru
My idea for the e-mail didn't fly. Our IRB wants the opt out on each page of the survey. :(

I turned off the XSS-Filter in global.
Then inserted your javascript at the end of the template.js file using the template editor

I don't see it either on preview mode or on the active survey.

eteam.ou.edu/survey/index.php?lang=en&si...oken=7bgma49ipptxjfw

Any idea why it wouldn't be working?

Thanks,
Betty

Please Log in to join the conversation.

More
5 years 5 months ago #64260 by tpartner
My script can't be added to template.js. It needs to be added to the source of a group description or a question.

The {TOKEN} keyword placeholder won't work in template.js (nor will any keyword placeholder).

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
5 years 5 months ago #64262 by dataguru
Let's see if I can make it work there.\

Thanks for your assistance.

Betty

Please Log in to join the conversation.

More
5 years 5 months ago #64263 by dataguru
I added it to both question groups, altered it just a little and it works perfectly!
<script type="text/javascript" charset="utf-8">
 
	$(document).ready(function() {
 
		// Find the survey ID
		if($('input#fieldnames').length != 0) {
			var fieldNames = $('input#fieldnames').attr('value');
			var tmp = fieldNames.split('X');
			var sID = tmp[0];
		}
 
		// Insert a new div after the progress bar
		$('<div id="optOutLink" />').insertBefore('#progress-wrapper');
 
		// Style the new div
		$('#optOutLink').css({
			'text-align':'center'
		});
 
		// Insert opt out url in the new div
		$('#optOutLink').html('<P><a href="optout.php?lang=en&sid='+sID+'&token={TOKEN}">Click here to opt out of this survey.</a></p><br>');
 
	});
 
</script>

Thanks again for your assistance!

FYI, I think our IT department is going to start using LS as well. Now I just have to try and figure out how to get a donation made to help support this project.

Betty

Please Log in to join the conversation.

More
5 years 5 months ago #64283 by tpartner
You're welcome.

You may want to change <P> to <p>. IE sometimes gets confused by uppercase tags.

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
5 years 5 months ago #64291 by dataguru
Thanks Tony. :)

Please Log in to join the conversation.

Imprint                   Privacy policy         General Terms & Conditions         Revocation information and revocation form