Redirect/change expired-inactive survey message

More
4 years 7 months ago #153503 by FaLifeTime
Hi: i need some help. I’m trying to change either the expired survey message or the deactivated survey message. I created one enrollment survey per course in the institution where I work and I want to show users another message if they try to access any survey link while is closed or expired; something like “The enrollment survey is closed, please check out …”. It could be a better solution also to redirect to a specific Scholl web page section giving a special message or some choices.

I read this thread without success.

Thanks,

4aLifeTime[/color][/color]
The topic has been locked.
More
4 years 7 months ago #153516 by tpartner
You have linked to another (old) thread but not explained what you have tried and how it failed. Also what is your LimeSurvey version?

Cheers,
Tony Partner

Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
The following user(s) said Thank You: FaLifeTime
The topic has been locked.
More
4 years 7 months ago #153524 by FaLifeTime
Hi tpartner,

thanks for your quick reply. Im using "Versión 2.05+ Build 150520". Concerning the thread i particularly tried your suggestion (below) adapting the messages into my default language: Spanish. It didnt work out, but i insist, my code knowledge is limited. Do i have any chance to redirect users if surveys are inactivated or expired?

Thanks!
4aLifeTime

$(document).ready(function() {

if($('p#tokenmessage').length > 0 && $('#tokenform').length == 0) {
var stringIndex = $('p#tokenmessage').text().indexOf('Diese Umfrage ist beendet und steht nicht mehr zur Verfügung);
if(stringIndex >= 0) {
$('p#tokenmessage').html('This survey is CLOSED!<br /><br />Go away!');
}
}

});
The topic has been locked.
More
4 years 7 months ago #153529 by tpartner
I see a bug (a missing closing quote) in that code so it should be:
$(document).ready(function() {
	if($('p#tokenmessage').length > 0 && $('#tokenform').length == 0) {
		var stringIndex = $('p#tokenmessage').text().indexOf('Diese Umfrage ist beendet und steht nicht mehr zur Verfügung');
		if(stringIndex >= 0) {
			$('p#tokenmessage').html('This survey is CLOSED!<br /><br />Go away!');
		}
	}
});

However, if using Spanish, you will need to replace the German string with whatever you see in Spanish. Probably this:
$(document).ready(function() {
	if($('p#tokenmessage').length > 0 && $('#tokenform').length == 0) {
		var stringIndex = $('p#tokenmessage').text().indexOf('Esta encuesta ya no está disponible');
		if(stringIndex >= 0) {
			$('p#tokenmessage').html('This survey is CLOSED!<br /><br />Go away!');
		}
	}
});

Having said that, if you want to redirect when the survey is closed instead of showing a custom message, try something like this (for Spanish):
$(document).ready(function() {
	if($('p#tokenmessage').length > 0 && $('#tokenform').length == 0) {
		var stringIndex = $('p#tokenmessage').text().indexOf('Esta encuesta ya no está disponible');
		if(stringIndex >= 0) {
			window.location = "http://google.com";
			$('p#tokenmessage').html('This survey is CLOSED!<br /><br />You are being redirected to our website.');
		}
	}
});

Cheers,
Tony Partner

Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
The topic has been locked.
More
4 years 7 months ago #153530 by FaLifeTime
Thanks tpartner. It works perfectly!

Cheers,
4aLifeTime
The topic has been locked.
More
3 years 6 months ago - 3 years 6 months ago #169542 by SCHEP23
Hi this workaround works also in version 3? Where I have to put the instruction?

Thanks
Laura
Last edit: 3 years 6 months ago by SCHEP23.
The topic has been locked.
More
3 years 5 months ago #169570 by tpartner
The code would be placed in custom.js.

Which workaround? There are two given above.

Cheers,
Tony Partner

Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
The following user(s) said Thank You: SCHEP23
The topic has been locked.
More
3 years 5 months ago #169575 by SCHEP23
I copy-paste the following in the custom.js of my theme:

$(document).ready(function() {
if($('p#tokenmessage').length > 0 && $('#tokenform').length === 0) {
var stringIndex = $('p#tokenmessage').text().indexOf('We are sorry but the survey is expired and no longer available');
if(stringIndex >= 0) {
window.location = "google.com";
$('p#tokenmessage').html('This survey is CLOSED!<br /><br />You are being redirected to our website.');
}
}
});

And nothing happened in error message. I'm using english and Limesurvey 3.7.2.

Thanks a lot for any suggestion
Laura
The topic has been locked.
More
3 years 5 months ago #169630 by tpartner
Place something like this is custom.js:

$(document).on('ready pjax:scriptcomplete',function(){
 
	var lsText = 'We are sorry but the survey is expired and no longer available.';
	var newText = 'This survey is CLOSED!<br /><br />You are being redirected to our website.';
 
	if($('p.message-0').length == 1 && $('p.message-0:first').text() == lsText) {			
		$('p.message-0:first').text(newText);
		window.location = "http://google.com";
	}
});

Cheers,
Tony Partner

Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
The topic has been locked.
More
3 years 5 months ago - 3 years 5 months ago #169695 by SCHEP23
Thanks, i paste this script in theme custom.js but nothing happened.
It's the right place?
Laura
Last edit: 3 years 5 months ago by SCHEP23.
The topic has been locked.
More
3 years 5 months ago #169700 by tpartner
Can you activate a test survey and give a link here?

Cheers,
Tony Partner

Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
The topic has been locked.
More
3 years 5 months ago #169723 by SCHEP23
Sorry, i cannot do that.
I'm not sure I putted the script in the right form: i did the following:
Configuration-->Advanced-->Themes
I choose the extended one i'm using for the survey and select Theme editor. Than I copied-pasted the script you provide me in the custom.js.
As I said before my expire message is always the same..
Hope this clarify a little
Thanks Laura
The topic has been locked.
More
3 years 5 months ago #169725 by tpartner
It may be a caching issue. Completely clear you cache before testing.

Try placing this simple alert in custom.js:

$(document).on('ready pjax:scriptcomplete',function(){
	alert('Page loaded.');
});

Cheers,
Tony Partner

Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
The topic has been locked.
More
3 years 5 months ago #169760 by SCHEP23
I cleared the cache and putted the alert in custom.js and I see the alert.
But the error custom message script is still not working
Laura
The topic has been locked.
More
3 years 5 months ago #169763 by tpartner
The workaround works for me. Unfortunately, I cannot debug your problem without seeing a test survey.

Cheers,
Tony Partner

Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
The topic has been locked.

Start now!

Just create your account and start using Limesurvey today.

Register now