Welcome, Guest
Username: Password: Remember me

TOPIC: Using {TOKEN:COMPLETED} in javascript

Using {TOKEN:COMPLETED} in javascript 2 years 10 months ago #67777

  • Fred
  • Fred's Avatar
  • OFFLINE
  • Gold Lime
  • Posts: 163
  • Thank you received: 5
  • Karma: 3
Sorry to ask so many questions recently. I tried to look this up in the forum and manual but couldn't find definite answer.

I have two surveys, A and B. Both are controlled access, by token, not anonymous, token persistence enabled.

I want to supply a URL with the token parameter to direct them to survey A. When survey A is complete, the end URL directs them to survey B and creates a token on the fly, using the same token as survey A.

Now suppose that someone completes survey A, then starts but doesn't complete survey B. Later they want to return and finish. They use the original URL, which will send them to survey A of course. I'd like LS to see that survey A is already complete and send them right to survey B.

My plan was to put a dummy question at the beginning with some javascript to test if {TOKEN:Completed} was = Y. But this isn't working. Is it because that field isn't accessible to javascript during runtime? Is there another way to force them to a new page (which could be the same as the end URL) if the survey is completed?
The administrator has disabled public write access.

Re: Using {TOKEN:COMPLETED} in javascript 2 years 10 months ago #67787

  • DenisChenu
  • DenisChenu's Avatar
  • OFFLINE
  • Moderator Lime
  • Posts: 6277
  • Thank you received: 801
  • Karma: 241
Hello,

There aren't {TOKEN:completed} possibility, because before 1.90, user can only access one time to each survey with token.

You can put your idea in Feature requests.

Here , i think the best think is to use an external php script. SOmething like that:

access.php?token=XXXXX

Get the token
  1. if survey A for this token aren't completed redirect to survey A
  2. if survey A is completed : create if not exist a new token for survey B
  3. if survey A is completed and a token not completed are here in survey B : redirect to survey B.
  4. if survey A and survey B are completed, thanks the person :)
The administrator has disabled public write access.

Re: Using {TOKEN:COMPLETED} in javascript 2 years 10 months ago #67795

  • Mazi
  • Mazi's Avatar
  • OFFLINE
  • LimeSurvey Team
  • Posts: 5324
  • Thank you received: 294
  • Karma: 249
Fred wrote:
My plan was to put a dummy question at the beginning with some javascript to test if {TOKEN:Completed} was = Y. But this isn't working. Is it because that field isn't accessible to javascript during runtime? Is there another way to force them to a new page (which could be the same as the end URL) if the survey is completed?
If the user completed survey A and the token can only be used ocne, there will be an error message that the current token was already used. You can edit the translation file to adapt the error message and include the link to the second survey there.

Best regards/Beste Grüße,
Dr. Marcel Minke
(Limesurvey Head of Support)
Need Help? We offer professional Limesurvey support
Contact: marcel.minke(at)limesurvey.org'"
The administrator has disabled public write access.

Re: Using {TOKEN:COMPLETED} in javascript 2 years 10 months ago #67829

  • Fred
  • Fred's Avatar
  • OFFLINE
  • Gold Lime
  • Posts: 163
  • Thank you received: 5
  • Karma: 3
Thanks Mazi, that might work although changing the error message would affect all surveys on the system. I didn't know about that translation file by the way; that could be handy in lots of other ways.

Note, what if I make the token for survey A usable for 1000 times so there's no error. Then it should start the survey and run my javascript. But it's still not working correctly, probably because it can't access that COMPLETED parameter from the browser. In the documentation it says the TOKEN fields available for piping, emails, etc. are only these. It doesn't explicitly say the COMPLETED field is accessible.

{TOKEN:FIRSTNAME} inserts the value from the "firstname" field in the tokens table
{TOKEN:LASTNAME} inserts the value from the "lastname" field in the tokens table
{TOKEN:EMAIL} inserts the value from the "email" field in the tokens table
{TOKEN:ATTRIBUTE_1} inserts the value from the "attribute_1" field in the tokens table
{TOKEN:ATTRIBUTE_2} inserts the value from the "attribute_2" field in the tokens table
The administrator has disabled public write access.

Re: Using {TOKEN:COMPLETED} in javascript 2 years 10 months ago #67865

  • Mazi
  • Mazi's Avatar
  • OFFLINE
  • LimeSurvey Team
  • Posts: 5324
  • Thank you received: 294
  • Karma: 249
Fred wrote:
Thanks Mazi, that might work although changing the error message would affect all surveys on the system. I didn't know about that <a href='docs.limesurvey.org/tiki-index.php?page=...anslating+LimeSurvey'>translation</a> file by the way; that could be handy in lots of other ways.
Another tip about the language files: You could copy all the content from the english language file to a language you never use, by using a raw text editor. Then you have a copy of the english langauge and you can change the message. At the survey settings you can then use the overworked not used anywhere else language as base language.

Best regards/Beste Grüße,
Dr. Marcel Minke
(Limesurvey Head of Support)
Need Help? We offer professional Limesurvey support
Contact: marcel.minke(at)limesurvey.org'"
The administrator has disabled public write access.
Moderators: ITEd
Time to create page: 0.126 seconds
Donation Image