Welcome to the LimeSurvey Community Forum

Ask the community, share ideas, and connect with other LimeSurvey users!

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

  • dataguru
  • dataguru's Avatar Topic Author
  • Offline
  • New Member
  • New Member
More
12 years 7 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
The topic has been locked.
  • tpartner
  • tpartner's Avatar
  • Away
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
12 years 7 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:
Code:
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.
The topic has been locked.
  • dataguru
  • dataguru's Avatar Topic Author
  • Offline
  • New Member
  • New Member
More
12 years 7 months ago - 12 years 7 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: 12 years 7 months ago by dataguru.
The topic has been locked.
  • tpartner
  • tpartner's Avatar
  • Away
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
12 years 7 months ago #64181 by tpartner
I haven't tested but maybe something like:
Code:
<a href="http://yourSurveySite/limesurvey//optout.php?lang=en&amp;sid=12345&amp;token={TOKEN}">Opt out</a>

Cheers,
Tony Partner

Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
The topic has been locked.
  • dataguru
  • dataguru's Avatar Topic Author
  • Offline
  • New Member
  • New Member
More
12 years 7 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
Code:
<p><a href="http://eteam.ou.edu/survey//optout.php?lang=en&amp;sid=<?php echo $scid; ?>&amp;token=<?php echo $clienttoken; ?>">Click here to opt out of this survey</a></p>

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

but it keeps removing the <?
The topic has been locked.
  • dataguru
  • dataguru's Avatar Topic Author
  • Offline
  • New Member
  • New Member
More
12 years 7 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.
The topic has been locked.
  • dataguru
  • dataguru's Avatar Topic Author
  • Offline
  • New Member
  • New Member
More
12 years 7 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.
Code:
$(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.
The topic has been locked.
  • tpartner
  • tpartner's Avatar
  • Away
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
12 years 7 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).
Code:
<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&amp;sid='+sID+'&amp;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.
The topic has been locked.
  • dataguru
  • dataguru's Avatar Topic Author
  • Offline
  • New Member
  • New Member
More
12 years 7 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
The topic has been locked.
  • dataguru
  • dataguru's Avatar Topic Author
  • Offline
  • New Member
  • New Member
More
12 years 7 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
The topic has been locked.
  • tpartner
  • tpartner's Avatar
  • Away
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
12 years 7 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.
The topic has been locked.
  • dataguru
  • dataguru's Avatar Topic Author
  • Offline
  • New Member
  • New Member
More
12 years 7 months ago #64262 by dataguru
Let's see if I can make it work there.\

Thanks for your assistance.

Betty
The topic has been locked.

Lime-years ahead

Online-surveys for every purse and purpose