Welcome, Guest
Username: Password: Remember me
  • Page:
  • 1
  • 2

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

How to add a button at end of a survey to go to an external URL? 1 year 7 months ago #91282

  • spt
  • spt's Avatar
  • OFFLINE
  • Fresh Lemon
  • Posts: 8
  • Karma: 0
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
The administrator has disabled public write access.

Re: How to add a button at end of a survey to go to an external URL? 1 year 7 months ago #91283

  • helper
  • helper's Avatar
  • OFFLINE
  • Expert Lime
  • Posts: 126
  • Thank you received: 18
  • Karma: 0
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).
The administrator has disabled public write access.

Re: How to add a button at end of a survey to go to an external URL? 1 year 7 months ago #91284

  • spt
  • spt's Avatar
  • OFFLINE
  • Fresh Lemon
  • Posts: 8
  • Karma: 0
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.
The administrator has disabled public write access.

Re: How to add a button at end of a survey to go to an external URL? 1 year 7 months ago #91286

  • helper
  • helper's Avatar
  • OFFLINE
  • Expert Lime
  • Posts: 126
  • Thank you received: 18
  • Karma: 0
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: 1 year 7 months ago by helper.
The administrator has disabled public write access.

Re: How to add a button at end of a survey to go to an external URL? 1 year 7 months ago #91287

  • holch
  • holch's Avatar
  • OFFLINE
  • LimeSurvey Team
  • Posts: 2621
  • Thank you received: 307
  • Karma: 113
Can't you just include something on the end page on template level?
Have a look at the manual! It is a really valuable source for information. Here some helpful links:
Manual (EN) | Question Types | Question Attributes | Workarounds

If you found this answer helpful and it saved you some time please consider a donation to the project to keep Limesurvey going!
The administrator has disabled public write access.

Re: How to add a button at end of a survey to go to an external URL? 1 year 7 months ago #91289

  • helper
  • helper's Avatar
  • OFFLINE
  • Expert Lime
  • Posts: 126
  • Thank you received: 18
  • Karma: 0
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 :)
The administrator has disabled public write access.

Re: How to add a button at end of a survey to go to an external URL? 1 year 7 months ago #91314

  • tpartner
  • tpartner's Avatar
  • OFFLINE
  • LimeSurvey Team
  • Posts: 4127
  • Thank you received: 761
  • Karma: 347
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.

LimeSurvey is open-source and run entirely by volunteers so please consider donating to support the project.
The administrator has disabled public write access.
The following user(s) said Thank You: spt

Re: How to add a button at end of a survey to go to an external URL? 1 year 7 months ago #91345

  • spt
  • spt's Avatar
  • OFFLINE
  • Fresh Lemon
  • Posts: 8
  • Karma: 0
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
The administrator has disabled public write access.

Re: How to add a button at end of a survey to go to an external URL? 1 year 7 months ago #91346

  • tpartner
  • tpartner's Avatar
  • OFFLINE
  • LimeSurvey Team
  • Posts: 4127
  • Thank you received: 761
  • Karma: 347
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.

LimeSurvey is open-source and run entirely by volunteers so please consider donating to support the project.
The administrator has disabled public write access.

Re: How to add a button at end of a survey to go to an external URL? 1 year 7 months ago #91354

  • spt
  • spt's Avatar
  • OFFLINE
  • Fresh Lemon
  • Posts: 8
  • Karma: 0
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
The administrator has disabled public write access.
  • Page:
  • 1
  • 2
Moderators: ITEd
Time to create page: 0.205 seconds
Donation Image