How to add a button at end of a survey to go to an external URL?

More
4 years 6 months ago #91282 by spt01
spt01 created the topic: How to add a button at end of a survey to go to an external URL?
Hello,

Does anyone know how to add a button at the end of a survey in order to go to an external URL?

I'm trying to change the source code, but was wondering if anyone has done this before.

Basically I'd like to add a "Preview" button next to "Submit" button at the last page of survey, such that when it's clicked, participants will be redirected to an external link (which will show the preview of current survey results in some format that we desire).

Thanks,
Anna

Please Log in to join the conversation.

More
4 years 6 months ago #91283 by helper
helper replied the topic: How to add a button at end of a survey to go to an external URL?
How is your technical level? If you have some technical expertise, you may want to consider putting in another button in the SurveyRuntimeHelper.php (in Version 2.00+ Build 130116 the buttons start at about line 1074).

Please Log in to join the conversation.

More
4 years 6 months ago #91284 by spt01
spt01 replied the topic: How to add a button at end of a survey to go to an external URL?
Thanks for your reply.

I've been looking at frontend_helper.php, in the surveymover() function, it makes more sense to me that I should add a button in the last if statement.

I do not see how we can add a button in the SurveyRuntimeHelper.php.

Maybe I'm wrong.

Please Log in to join the conversation.

More
4 years 6 months ago - 4 years 6 months ago #91286 by helper
helper replied the topic: How to add a button at end of a survey to go to an external URL?
Good catch... seems there are actually a couple of methods that end a survey and they all have a little different method. For example, grep/search for the following term:

javascript:document.limesurvey.move.value = 'movesubmit';

You will find this at least three times within the codebase. Another alternative might be to use CSS to change content or append a static button to the existing button (I think that jQuery has a shortcut for this - charlie.griefer.com/blog/2009/09/17/jque...dding-form-elements/ ).
Last Edit: 4 years 6 months ago by helper.

Please Log in to join the conversation.

More
4 years 6 months ago #91287 by holch
holch replied the topic: How to add a button at end of a survey to go to an external URL?
Can't you just include something on the end page on template level?

I'm not a LimeSurvey GmbH member. I answer at the LimeSurvey forum in my spare time. No support via private message.
Some helpful links: Manual (EN) | Question Types | Workarounds

Please Log in to join the conversation.

More
4 years 6 months ago #91289 by helper
helper replied the topic: How to add a button at end of a survey to go to an external URL?
Actually, if you are not concerned about having this link button on the same page as the submit you could put a static HTML button on the end message (Edit survey text messages). That would probably be the least painful :)

Please Log in to join the conversation.

More
4 years 6 months ago #91314 by tpartner
tpartner replied the topic: How to add a button at end of a survey to go to an external URL?
A couple of JavaScript solutions...

Assumptions:
- you are using LS 2
- you want the button on the last question page (not the "End" page)
- you want the link opened in a new window

1) If you want to do this for a single survey, set up your survey to use JavaScript and add the following script to the source of one of the questions on the last question page.
<script type="text/javascript" charset="utf-8">
	$(document).ready(function(){
		var buttonText = 'Review Answers';
		var url = 'http://someRedirectLink.com';
 
		$('#movesubmitbtn').before('<button id="movereviewbtn" type="button">'+buttonText+'</button>');
		$('#movereviewbtn').click(function() {
			window.open(url, '_blank');
		}).button();
	});
</script>

2) If you want do do it for several surveys using the same template, add this to the end of template.js:
$(document).ready(function(){
	if($('#movesubmitbtn').length > 0) {
		var buttonText = 'Review Answers';
		var url = 'http://someRedirectLink.com';
 
		$('#movesubmitbtn').before('<button id="movereviewbtn" type="button">'+buttonText+'</button>');
		$('#movereviewbtn').click(function() {
			window.open(url, '_blank');
		}).button();
	}
});

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: spt01

Please Log in to join the conversation.

More
4 years 6 months ago #91345 by spt01
spt01 replied the topic: How to add a button at end of a survey to go to an external URL?
Hi Tony,

Thanks for your reply.

I've tried (1), it's successful.

What I need is (2) and I've done per your instruction above, i.e., adding the codes at the end of template.js (I am using 'default' template), but nothing changed. Do I need to setup any other things to make it work?

Thanks,
Anna

Please Log in to join the conversation.

More
4 years 6 months ago #91346 by tpartner
tpartner replied the topic: How to add a button at end of a survey to go to an external URL?

Do I need to setup any other things to make it work?

No, that should work as-is. I assume you are working in a copy of the default template - you can't modify the original.

Are you getting any JavaScript errors?

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
4 years 6 months ago #91354 by spt01
spt01 replied the topic: How to add a button at end of a survey to go to an external URL?
Hi Tony,

Thank you!!! It works now (after making a copy of the template).

For the external link, do you know if it's possible to pass parameters such as survey ID & participant's token in template.js, for example:

var url = 'http://someRedirectLink.com?sid={SID}&token={TOKEN}';

I've tried using this, not working so far, maybe I have to use different notations.

Thanks,
Anna

Please Log in to join the conversation.

More
4 years 6 months ago #91358 by spt01
spt01 replied the topic: How to add a button at end of a survey to go to an external URL?
Hi,

I think I find the notations:

var url = 'someRedirectLink.com?sid='+$('#sid').val()+'&token='+$('#token').val();

Thanks again for your help! Really appreciate it.
Anna

Please Log in to join the conversation.

Did you already participate in our customer survey?

Don't miss your chance for great prices.

Please click here to participate:

Start now

Start now!

Just create your account and start using Limesurvey today.

Register now