Hi,
time to go on with this thread
I'd like to use survey specific messages for undefined tokenlabel, tokentext, tokenerror, i.e. the page that comes up when someone enters a sid that does not exist. I use LS 2.6.7LTS.
I tried to use an if-condition to discriminate between a closed (only participants with token can take part) survey with sid = 111111 and all the other surveys - but that failed. I'm still a novice in JS and probably overlook something decisive. Who can help?
I started with Denis' Code (
www.limesurvey.org/forum/can-i-do-this-w...ication-copied#78077
) which works perfectly. It replaces the given messages by the ones entered for tokenlabel tokentext, tokenerror.
Code:
$(document).ready(function(){
if (typeof tokenlabel === "undefined"){
tokenlabel ="YOUR TOKEN LABEL : ";
}
if (typeof tokentext === "undefined"){
tokentext ="YOUR TOKEN TEXT DESCRIPTION";
}
if (typeof tokenerror === "undefined"){
tokenerror ="<br><br><strong class='error'>YOUR ERROR MESSAGE.</strong>";
}
if ($("#tokenform").length )
{
$("#tokenmessage").html(tokentext);
$("label[for='token']").text(tokenlabel);
}
else
{
$("#tokenmessage").html(tokentext+tokenerror);
}
})
Now my idea was to split this into two. I tried with two if conditions - one for SID = 111111 and one for the other cases. I thought it's possible to get the SID and use it in the if. (I put in a little window.alert to show me the content of this_surveyId, that should contain the SID)
Code:
$(document).ready(function(){
var this_surveyId = '{SID}'; /*gets the SID */
window.alert(this_surveyId); /*returns the string "{SID}" and not the actual SID - I guess, I'm the only surprised here :-)*/
if (this_surveyId === 111111){
if (typeof tokenlabel === "undefined"){
tokenlabel ="1 YOUR TOKEN LABEL : ";
}
if (typeof tokentext === "undefined"){
tokentext ="1 YOUR TOKEN TEXT DESCRIPTION {SID}";
}
if (typeof tokenerror === "undefined"){
tokenerror ="1 <br><br><strong class='error'>YOUR ERROR MESSAGE.</strong>";
}
}
if (this_surveyId !== 111111){
if (typeof tokenlabel === "undefined"){
tokenlabel ="2 YOUR TOKEN LABEL : ";
}
if (typeof tokentext === "undefined"){
tokentext ="2 YOUR TOKEN TEXT DESCRIPTION {SID}";
}
if (typeof tokenerror === "undefined"){
tokenerror ="2 <br><br><strong class='error'>YOUR ERROR MESSAGE.</strong>";
}
}
if ($("#tokenform").length )
{
$("#tokenmessage").html(tokentext);
$("label[for='token']").text(tokenlabel);
}
else
{
$("#tokenmessage").html(tokentext+tokenerror);
}
})
But: When I enter the survey url, e.g.
www.foo.com/ls/index.php/survey/index/sid/111111
- I do not get the expected "1 YOUR TOKEN TEXT DESCRIPTION 1 {SID}" and "1 YOUR TOKEN LABEL : ", but "2 YOUR TOKEN TEXT DESCRIPTION {SID}";
The problem seems: I somehow fail to get the SID - as the window.alert and the output shows. It returns "{SID}" as a string but not the SID itself.
Hm... how could I achieve this? Sorry, if I overlook something obvious.
I appreciate any help!
Thanks for your time and all the best,
G